diff --git a/ogr/ogrsf_frmts/georss/ogr_georss.h b/ogr/ogrsf_frmts/georss/ogr_georss.h index bd370d5a809f..3d3886a893ea 100644 --- a/ogr/ogrsf_frmts/georss/ogr_georss.h +++ b/ogr/ogrsf_frmts/georss/ogr_georss.h @@ -38,6 +38,8 @@ #include "ogr_expat.h" #endif +constexpr int PARSER_BUF_SIZE = 8192; + class OGRGeoRSSDataSource; typedef enum diff --git a/ogr/ogrsf_frmts/georss/ogrgeorssdatasource.cpp b/ogr/ogrsf_frmts/georss/ogrgeorssdatasource.cpp index 085b6b4c3adb..8d8ce12d0e15 100644 --- a/ogr/ogrsf_frmts/georss/ogrgeorssdatasource.cpp +++ b/ogr/ogrsf_frmts/georss/ogrgeorssdatasource.cpp @@ -216,7 +216,7 @@ void OGRGeoRSSDataSource::dataHandlerValidateCbk(const char * /* data */, int /* nLen */) { nDataHandlerCounter++; - if (nDataHandlerCounter >= BUFSIZ) + if (nDataHandlerCounter >= PARSER_BUF_SIZE) { CPLError(CE_Failure, CPLE_AppDefined, "File probably corrupted (million laugh pattern)"); @@ -270,7 +270,7 @@ int OGRGeoRSSDataSource::Open(const char *pszFilename, int bUpdateIn) XML_SetCharacterDataHandler(oParser, ::dataHandlerValidateCbk); oCurrentParser = oParser; - char aBuf[BUFSIZ]; + std::vector aBuf(PARSER_BUF_SIZE); int nDone = 0; unsigned int nLen = 0; int nCount = 0; @@ -282,18 +282,19 @@ int OGRGeoRSSDataSource::Open(const char *pszFilename, int bUpdateIn) do { nDataHandlerCounter = 0; - nLen = static_cast(VSIFReadL(aBuf, 1, sizeof(aBuf), fp)); + nLen = static_cast( + VSIFReadL(aBuf.data(), 1, aBuf.size(), fp)); nDone = VSIFEofL(fp); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { - if (nLen <= BUFSIZ - 1) + if (nLen <= PARSER_BUF_SIZE - 1) aBuf[nLen] = 0; else - aBuf[BUFSIZ - 1] = 0; + aBuf[PARSER_BUF_SIZE - 1] = 0; - if (strstr(aBuf, " aBuf(PARSER_BUF_SIZE); do { unsigned int nLen = static_cast( - VSIFReadL(aBuf, 1, sizeof(aBuf), fpGeoRSS)); + VSIFReadL(aBuf.data(), 1, aBuf.size(), fpGeoRSS)); nDone = VSIFEofL(fpGeoRSS); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { CPLError(CE_Failure, CPLE_AppDefined, "XML parsing of GeoRSS file failed : %s " @@ -1785,15 +1785,16 @@ void OGRGeoRSSLayer::LoadSchema() nTotalFeatureCount = 0; setOfFoundFields = nullptr; - char aBuf[BUFSIZ] = {}; + std::vector aBuf(PARSER_BUF_SIZE); int nDone = 0; do { nDataHandlerCounter = 0; unsigned int nLen = - (unsigned int)VSIFReadL(aBuf, 1, sizeof(aBuf), fpGeoRSS); + (unsigned int)VSIFReadL(aBuf.data(), 1, aBuf.size(), fpGeoRSS); nDone = VSIFEofL(fpGeoRSS); - if (XML_Parse(oSchemaParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oSchemaParser, aBuf.data(), nLen, nDone) == + XML_STATUS_ERROR) { CPLError( CE_Failure, CPLE_AppDefined, @@ -2209,7 +2210,7 @@ void OGRGeoRSSLayer::dataHandlerLoadSchemaCbk(const char *data, int nLen) return; nDataHandlerCounter++; - if (nDataHandlerCounter >= BUFSIZ) + if (nDataHandlerCounter >= PARSER_BUF_SIZE) { CPLError(CE_Failure, CPLE_AppDefined, "File probably corrupted (million laugh pattern)"); diff --git a/ogr/ogrsf_frmts/gpx/ogr_gpx.h b/ogr/ogrsf_frmts/gpx/ogr_gpx.h index a39f57cbf4cc..8ad24ecdd3a7 100644 --- a/ogr/ogrsf_frmts/gpx/ogr_gpx.h +++ b/ogr/ogrsf_frmts/gpx/ogr_gpx.h @@ -48,6 +48,8 @@ typedef enum GPX_TRACK_POINT, } GPXGeometryType; +constexpr int PARSER_BUF_SIZE = 8192; + /************************************************************************/ /* OGRGPXLayer */ /************************************************************************/ diff --git a/ogr/ogrsf_frmts/gpx/ogrgpxdatasource.cpp b/ogr/ogrsf_frmts/gpx/ogrgpxdatasource.cpp index cd5bbaae85d9..896f7ac75167 100644 --- a/ogr/ogrsf_frmts/gpx/ogrgpxdatasource.cpp +++ b/ogr/ogrsf_frmts/gpx/ogrgpxdatasource.cpp @@ -443,7 +443,7 @@ void OGRGPXDataSource::dataHandlerValidateCbk(const char *data, int nLen) } nDataHandlerCounter++; - if (nDataHandlerCounter >= BUFSIZ) + if (nDataHandlerCounter >= PARSER_BUF_SIZE) { CPLError(CE_Failure, CPLE_AppDefined, "File probably corrupted (million laugh pattern)"); @@ -509,7 +509,7 @@ int OGRGPXDataSource::Open(const char *pszFilename, int bUpdateIn) ::endElementValidateCbk); XML_SetCharacterDataHandler(oParser, ::dataHandlerValidateCbk); - char aBuf[BUFSIZ]; + std::vector aBuf(PARSER_BUF_SIZE); int nDone = 0; unsigned int nLen = 0; int nCount = 0; @@ -522,16 +522,17 @@ int OGRGPXDataSource::Open(const char *pszFilename, int bUpdateIn) do { nDataHandlerCounter = 0; - nLen = static_cast(VSIFReadL(aBuf, 1, sizeof(aBuf), fp)); + nLen = static_cast( + VSIFReadL(aBuf.data(), 1, aBuf.size(), fp)); nTotalBytesRead += nLen; nDone = VSIFEofL(fp); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { - if (nLen <= BUFSIZ - 1) + if (nLen <= PARSER_BUF_SIZE - 1) aBuf[nLen] = 0; else - aBuf[BUFSIZ - 1] = 0; - if (strstr(aBuf, "= BUFSIZ) + if (nDataHandlerCounter >= PARSER_BUF_SIZE) { CPLError(CE_Failure, CPLE_AppDefined, "File probably corrupted (million laugh pattern)"); @@ -1102,8 +1102,7 @@ OGRFeature *OGRGPXLayer::GetNextFeature() if (VSIFEofL(fpGPX)) return nullptr; - char aBuf[BUFSIZ]; - + std::vector aBuf(PARSER_BUF_SIZE); CPLFree(ppoFeatureTab); ppoFeatureTab = nullptr; nFeatureTabLength = 0; @@ -1114,10 +1113,10 @@ OGRFeature *OGRGPXLayer::GetNextFeature() do { nDataHandlerCounter = 0; - unsigned int nLen = - static_cast(VSIFReadL(aBuf, 1, sizeof(aBuf), fpGPX)); + unsigned int nLen = static_cast( + VSIFReadL(aBuf.data(), 1, aBuf.size(), fpGPX)); nDone = VSIFEofL(fpGPX); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { CPLError(CE_Failure, CPLE_AppDefined, "XML parsing of GPX file failed : " @@ -1960,15 +1959,16 @@ void OGRGPXLayer::LoadExtensionsSchema() nWithoutEventCounter = 0; bStopParsing = false; - char aBuf[BUFSIZ]; + std::vector aBuf(PARSER_BUF_SIZE); int nDone = 0; do { nDataHandlerCounter = 0; - unsigned int nLen = - static_cast(VSIFReadL(aBuf, 1, sizeof(aBuf), fpGPX)); + unsigned int nLen = static_cast( + VSIFReadL(aBuf.data(), 1, aBuf.size(), fpGPX)); nDone = VSIFEofL(fpGPX); - if (XML_Parse(oSchemaParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oSchemaParser, aBuf.data(), nLen, nDone) == + XML_STATUS_ERROR) { CPLError( CE_Failure, CPLE_AppDefined, @@ -2218,7 +2218,7 @@ void OGRGPXLayer::dataHandlerLoadSchemaCbk(const char *data, int nLen) return; nDataHandlerCounter++; - if (nDataHandlerCounter >= BUFSIZ) + if (nDataHandlerCounter >= PARSER_BUF_SIZE) { CPLError(CE_Failure, CPLE_AppDefined, "File probably corrupted (million laugh pattern)"); diff --git a/ogr/ogrsf_frmts/jml/ogrjmllayer.cpp b/ogr/ogrsf_frmts/jml/ogrjmllayer.cpp index 862047285e56..74a25d0dc855 100644 --- a/ogr/ogrsf_frmts/jml/ogrjmllayer.cpp +++ b/ogr/ogrsf_frmts/jml/ogrjmllayer.cpp @@ -29,6 +29,8 @@ #include "ogr_jml.h" #include "ogr_p.h" +constexpr int PARSER_BUF_SIZE = 8192; + #ifdef HAVE_EXPAT /************************************************************************/ @@ -397,7 +399,7 @@ void OGRJMLLayer::dataHandlerCbk(const char *data, int nLen) return; nDataHandlerCounter++; - if (nDataHandlerCounter >= BUFSIZ) + if (nDataHandlerCounter >= PARSER_BUF_SIZE) { CPLError(CE_Failure, CPLE_AppDefined, "File probably corrupted (million laugh pattern)"); @@ -434,7 +436,7 @@ OGRFeature *OGRJMLLayer::GetNextFeature() if (VSIFEofL(fp)) return nullptr; - char aBuf[BUFSIZ]; + std::vector aBuf(PARSER_BUF_SIZE); nFeatureTabLength = 0; nFeatureTabIndex = 0; @@ -445,9 +447,10 @@ OGRFeature *OGRJMLLayer::GetNextFeature() do { nDataHandlerCounter = 0; - unsigned int nLen = (unsigned int)VSIFReadL(aBuf, 1, sizeof(aBuf), fp); + unsigned int nLen = + (unsigned int)VSIFReadL(aBuf.data(), 1, aBuf.size(), fp); nDone = VSIFEofL(fp); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { CPLError(CE_Failure, CPLE_AppDefined, "XML parsing of JML file failed : %s " @@ -505,15 +508,15 @@ void OGRJMLLayer::LoadSchema() VSIFSeekL(fp, 0, SEEK_SET); - char aBuf[BUFSIZ]; + std::vector aBuf(PARSER_BUF_SIZE); int nDone = 0; do { nDataHandlerCounter = 0; - const unsigned int nLen = - static_cast(VSIFReadL(aBuf, 1, sizeof(aBuf), fp)); + const unsigned int nLen = static_cast( + VSIFReadL(aBuf.data(), 1, aBuf.size(), fp)); nDone = VSIFEofL(fp); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { CPLError(CE_Failure, CPLE_AppDefined, "XML parsing of JML file failed : %s at line %d, " diff --git a/ogr/ogrsf_frmts/kml/kml.cpp b/ogr/ogrsf_frmts/kml/kml.cpp index af85da26bd30..aa18e88664e3 100644 --- a/ogr/ogrsf_frmts/kml/kml.cpp +++ b/ogr/ogrsf_frmts/kml/kml.cpp @@ -41,6 +41,8 @@ #include "expat.h" #endif +constexpr int PARSER_BUF_SIZE = 8192; + KML::KML() : poTrunk_(nullptr), nNumLayers_(-1), papoLayers_(nullptr), nDepth_(0), validity(KML_VALIDITY_UNKNOWN), pKMLFile_(nullptr), poCurrent_(nullptr), @@ -95,15 +97,15 @@ bool KML::parse() int nDone = 0; int nLen = 0; - char aBuf[BUFSIZ] = {0}; + std::vector aBuf(PARSER_BUF_SIZE); bool bError = false; do { nDataHandlerCounter = 0; - nLen = (int)VSIFReadL(aBuf, 1, sizeof(aBuf), pKMLFile_); + nLen = (int)VSIFReadL(aBuf.data(), 1, aBuf.size(), pKMLFile_); nDone = VSIFEofL(pKMLFile_); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { CPLError(CE_Failure, CPLE_AppDefined, "XML parsing of KML file failed : %s at line %d, " @@ -184,23 +186,25 @@ void KML::checkValidity() int nDone = 0; int nLen = 0; - char aBuf[BUFSIZ] = {0}; + std::vector aBuf(PARSER_BUF_SIZE); // Parses the file until we find the first element. do { nDataHandlerCounter = 0; - nLen = static_cast(VSIFReadL(aBuf, 1, sizeof(aBuf), pKMLFile_)); + nLen = + static_cast(VSIFReadL(aBuf.data(), 1, aBuf.size(), pKMLFile_)); nDone = VSIFEofL(pKMLFile_); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { - if (nLen <= BUFSIZ - 1) + if (nLen <= PARSER_BUF_SIZE - 1) aBuf[nLen] = 0; else - aBuf[BUFSIZ - 1] = 0; - if (strstr(aBuf, " 0 && validity == KML_VALIDITY_UNKNOWN && nCount < 50); @@ -370,7 +374,7 @@ void XMLCALL KML::dataHandlerValidate(void *pUserData, KML *poKML = static_cast(pUserData); poKML->nDataHandlerCounter++; - if (poKML->nDataHandlerCounter >= BUFSIZ) + if (poKML->nDataHandlerCounter >= PARSER_BUF_SIZE) { CPLError(CE_Failure, CPLE_AppDefined, "File probably corrupted (million laugh pattern)"); @@ -535,7 +539,7 @@ void XMLCALL KML::dataHandler(void *pUserData, const char *pszData, int nLen) return; poKML->nDataHandlerCounter++; - if (poKML->nDataHandlerCounter >= BUFSIZ) + if (poKML->nDataHandlerCounter >= PARSER_BUF_SIZE) { CPLError(CE_Failure, CPLE_AppDefined, "File probably corrupted (million laugh pattern)"); diff --git a/ogr/ogrsf_frmts/lvbag/ogr_lvbag.h b/ogr/ogrsf_frmts/lvbag/ogr_lvbag.h index c4da66721388..f54548cf22c3 100644 --- a/ogr/ogrsf_frmts/lvbag/ogr_lvbag.h +++ b/ogr/ogrsf_frmts/lvbag/ogr_lvbag.h @@ -57,6 +57,7 @@ using LayerVector = std::vector>; /************************************************************************/ /* OGRLVBAGLayer */ /************************************************************************/ +constexpr int PARSER_BUF_SIZE = 8192; class OGRLVBAGLayer final : public OGRAbstractProxiedLayer, public OGRGetNextFeatureThroughRaw @@ -103,7 +104,7 @@ class OGRLVBAGLayer final : public OGRAbstractProxiedLayer, CPLString osAttributeString; bool bCollectData; - char aBuf[BUFSIZ]; + std::vector aBuf = std::vector(PARSER_BUF_SIZE); void AddSpatialRef(OGRwkbGeometryType eTypeIn); void AddOccurrenceFieldDefn(); diff --git a/ogr/ogrsf_frmts/lvbag/ogrlvbaglayer.cpp b/ogr/ogrsf_frmts/lvbag/ogrlvbaglayer.cpp index ec3127472896..d3005020f391 100644 --- a/ogr/ogrsf_frmts/lvbag/ogrlvbaglayer.cpp +++ b/ogr/ogrsf_frmts/lvbag/ogrlvbaglayer.cpp @@ -58,8 +58,6 @@ OGRLVBAGLayer::OGRLVBAGLayer(const char *pszFilename, OGRLayerPool *poPoolIn, SetDescription(CPLGetBasename(pszFilename)); poFeatureDefn->Reference(); - - memset(aBuf, '\0', sizeof(aBuf)); } /************************************************************************/ @@ -862,12 +860,11 @@ void OGRLVBAGLayer::ParseDocument() case XML_INITIALIZED: case XML_PARSING: { - memset(aBuf, '\0', sizeof(aBuf)); const unsigned int nLen = static_cast( - VSIFReadL(aBuf, 1, sizeof(aBuf), fp)); + VSIFReadL(aBuf.data(), 1, aBuf.size(), fp)); - if (IsParserFinished( - XML_Parse(oParser.get(), aBuf, nLen, VSIFEofL(fp)))) + if (IsParserFinished(XML_Parse(oParser.get(), aBuf.data(), nLen, + VSIFEofL(fp)))) return; break; diff --git a/ogr/ogrsf_frmts/ods/ogrodsdatasource.cpp b/ogr/ogrsf_frmts/ods/ogrodsdatasource.cpp index 56a6ede962a9..7768aa1d4408 100644 --- a/ogr/ogrsf_frmts/ods/ogrodsdatasource.cpp +++ b/ogr/ogrsf_frmts/ods/ogrodsdatasource.cpp @@ -39,6 +39,8 @@ namespace OGRODS { +constexpr int PARSER_BUF_SIZE = 8192; + /************************************************************************/ /* ODSCellEvaluator */ /************************************************************************/ @@ -447,7 +449,7 @@ void OGRODSDataSource::dataHandlerCbk(const char *data, int nLen) return; nDataHandlerCounter++; - if (nDataHandlerCounter >= BUFSIZ) + if (nDataHandlerCounter >= PARSER_BUF_SIZE) { CPLError(CE_Failure, CPLE_AppDefined, "File probably corrupted (million laugh pattern)"); @@ -1300,15 +1302,15 @@ void OGRODSDataSource::AnalyseFile() VSIFSeekL(fpContent, 0, SEEK_SET); - char aBuf[BUFSIZ]; + std::vector aBuf(PARSER_BUF_SIZE); int nDone = 0; do { nDataHandlerCounter = 0; unsigned int nLen = static_cast( - VSIFReadL(aBuf, 1, sizeof(aBuf), fpContent)); + VSIFReadL(aBuf.data(), 1, aBuf.size(), fpContent)); nDone = VSIFEofL(fpContent); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { CPLError(CE_Failure, CPLE_AppDefined, "XML parsing of ODS file failed : %s at line %d, " @@ -1441,7 +1443,7 @@ void OGRODSDataSource::dataHandlerStylesCbk(const char *data, int nLen) return; nDataHandlerCounter++; - if (nDataHandlerCounter >= BUFSIZ) + if (nDataHandlerCounter >= PARSER_BUF_SIZE) { CPLError(CE_Failure, CPLE_AppDefined, "File probably corrupted (million laugh pattern)"); @@ -1483,15 +1485,15 @@ void OGRODSDataSource::AnalyseSettings() VSIFSeekL(fpSettings, 0, SEEK_SET); - char aBuf[BUFSIZ]; + std::vector aBuf(PARSER_BUF_SIZE); int nDone = 0; do { nDataHandlerCounter = 0; unsigned int nLen = - (unsigned int)VSIFReadL(aBuf, 1, sizeof(aBuf), fpSettings); + (unsigned int)VSIFReadL(aBuf.data(), 1, aBuf.size(), fpSettings); nDone = VSIFEofL(fpSettings); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { CPLError(CE_Failure, CPLE_AppDefined, "XML parsing of styles.xml file failed : %s at line %d, " diff --git a/ogr/ogrsf_frmts/svg/ogr_svg.h b/ogr/ogrsf_frmts/svg/ogr_svg.h index da983fa230be..bbef5aeb9e22 100644 --- a/ogr/ogrsf_frmts/svg/ogr_svg.h +++ b/ogr/ogrsf_frmts/svg/ogr_svg.h @@ -45,6 +45,8 @@ typedef enum SVG_POLYGONS, } SVGGeometryType; +constexpr int PARSER_BUF_SIZE = 8192; + /************************************************************************/ /* OGRSVGLayer */ /************************************************************************/ diff --git a/ogr/ogrsf_frmts/svg/ogrsvgdatasource.cpp b/ogr/ogrsf_frmts/svg/ogrsvgdatasource.cpp index fd7d7c71cc41..0a5bafa78e13 100644 --- a/ogr/ogrsf_frmts/svg/ogrsvgdatasource.cpp +++ b/ogr/ogrsf_frmts/svg/ogrsvgdatasource.cpp @@ -108,7 +108,7 @@ void OGRSVGDataSource::dataHandlerValidateCbk(CPL_UNUSED const char *data, CPL_UNUSED int nLen) { nDataHandlerCounter++; - if (nDataHandlerCounter >= BUFSIZ) + if (nDataHandlerCounter >= PARSER_BUF_SIZE) { CPLError(CE_Failure, CPLE_AppDefined, "File probably corrupted (million laugh pattern)"); @@ -165,7 +165,7 @@ int OGRSVGDataSource::Open(const char *pszFilename) XML_SetElementHandler(oParser, ::startElementValidateCbk, nullptr); XML_SetCharacterDataHandler(oParser, ::dataHandlerValidateCbk); - char aBuf[BUFSIZ]; + std::vector aBuf(PARSER_BUF_SIZE); int nDone = 0; unsigned int nLen = 0; int nCount = 0; @@ -177,15 +177,15 @@ int OGRSVGDataSource::Open(const char *pszFilename) do { nDataHandlerCounter = 0; - nLen = (unsigned int)VSIFReadL(aBuf, 1, sizeof(aBuf), fp); + nLen = (unsigned int)VSIFReadL(aBuf.data(), 1, aBuf.size(), fp); nDone = VSIFEofL(fp); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { - if (nLen <= BUFSIZ - 1) + if (nLen <= PARSER_BUF_SIZE - 1) aBuf[nLen] = 0; else - aBuf[BUFSIZ - 1] = 0; - if (strstr(aBuf, "= BUFSIZ) + if (nDataHandlerCounter >= PARSER_BUF_SIZE) { CPLError(CE_Failure, CPLE_AppDefined, "File probably corrupted (million laugh pattern)"); @@ -539,7 +539,7 @@ OGRFeature *OGRSVGLayer::GetNextFeature() if (VSIFEofL(fpSVG)) return nullptr; - char aBuf[BUFSIZ]; + std::vector aBuf(PARSER_BUF_SIZE); CPLFree(ppoFeatureTab); ppoFeatureTab = nullptr; @@ -553,9 +553,9 @@ OGRFeature *OGRSVGLayer::GetNextFeature() { nDataHandlerCounter = 0; unsigned int nLen = - (unsigned int)VSIFReadL(aBuf, 1, sizeof(aBuf), fpSVG); + (unsigned int)VSIFReadL(aBuf.data(), 1, aBuf.size(), fpSVG); nDone = VSIFEofL(fpSVG); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { CPLError( CE_Failure, CPLE_AppDefined, @@ -657,15 +657,16 @@ void OGRSVGLayer::LoadSchema() nWithoutEventCounter = 0; bStopParsing = false; - char aBuf[BUFSIZ]; + std::vector aBuf(PARSER_BUF_SIZE); int nDone = 0; do { nDataHandlerCounter = 0; unsigned int nLen = - (unsigned int)VSIFReadL(aBuf, 1, sizeof(aBuf), fpSVG); + (unsigned int)VSIFReadL(aBuf.data(), 1, aBuf.size(), fpSVG); nDone = VSIFEofL(fpSVG); - if (XML_Parse(oSchemaParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oSchemaParser, aBuf.data(), nLen, nDone) == + XML_STATUS_ERROR) { CPLError( CE_Failure, CPLE_AppDefined, @@ -782,7 +783,7 @@ void OGRSVGLayer::dataHandlerLoadSchemaCbk(CPL_UNUSED const char *data, return; nDataHandlerCounter++; - if (nDataHandlerCounter >= BUFSIZ) + if (nDataHandlerCounter >= PARSER_BUF_SIZE) { CPLError(CE_Failure, CPLE_AppDefined, "File probably corrupted (million laugh pattern)"); diff --git a/ogr/ogrsf_frmts/xlsx/ogrxlsxdatasource.cpp b/ogr/ogrsf_frmts/xlsx/ogrxlsxdatasource.cpp index 5b92781e7f7f..ae4836e6c832 100644 --- a/ogr/ogrsf_frmts/xlsx/ogrxlsxdatasource.cpp +++ b/ogr/ogrsf_frmts/xlsx/ogrxlsxdatasource.cpp @@ -37,6 +37,8 @@ namespace OGRXLSX { +constexpr int PARSER_BUF_SIZE = 8192; + constexpr int NUMBER_OF_DAYS_BETWEEN_1900_AND_1970 = 25569; constexpr int NUMBER_OF_SECONDS_PER_DAY = 86400; @@ -441,7 +443,7 @@ void OGRXLSXDataSource::dataHandlerCbk(const char *data, int nLen) return; nDataHandlerCounter++; - if (nDataHandlerCounter >= BUFSIZ) + if (nDataHandlerCounter >= PARSER_BUF_SIZE) { CPLError(CE_Failure, CPLE_AppDefined, "File probably corrupted (million laugh pattern)"); @@ -1215,14 +1217,15 @@ void OGRXLSXDataSource::BuildLayer(OGRXLSXLayer *poLayer) stateStack[0].eVal = STATE_DEFAULT; stateStack[0].nBeginDepth = 0; - char aBuf[BUFSIZ]; + std::vector aBuf(PARSER_BUF_SIZE); int nDone = 0; do { nDataHandlerCounter = 0; - unsigned int nLen = (unsigned int)VSIFReadL(aBuf, 1, sizeof(aBuf), fp); + unsigned int nLen = + (unsigned int)VSIFReadL(aBuf.data(), 1, aBuf.size(), fp); nDone = VSIFEofL(fp); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { CPLError(CE_Failure, CPLE_AppDefined, "XML parsing of %s file failed : %s at line %d, column %d", @@ -1348,7 +1351,7 @@ void OGRXLSXDataSource::dataHandlerSSCbk(const char *data, int nLen) return; nDataHandlerCounter++; - if (nDataHandlerCounter >= BUFSIZ) + if (nDataHandlerCounter >= PARSER_BUF_SIZE) { CPLError(CE_Failure, CPLE_AppDefined, "File probably corrupted (million laugh pattern)"); @@ -1398,15 +1401,15 @@ void OGRXLSXDataSource::AnalyseSharedStrings(VSILFILE *fpSharedStrings) stateStack[0].eVal = STATE_DEFAULT; stateStack[0].nBeginDepth = 0; - char aBuf[BUFSIZ]; + std::vector aBuf(PARSER_BUF_SIZE); int nDone = 0; do { nDataHandlerCounter = 0; - unsigned int nLen = - (unsigned int)VSIFReadL(aBuf, 1, sizeof(aBuf), fpSharedStrings); + unsigned int nLen = (unsigned int)VSIFReadL(aBuf.data(), 1, aBuf.size(), + fpSharedStrings); nDone = VSIFEofL(fpSharedStrings); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { CPLError(CE_Failure, CPLE_AppDefined, "XML parsing of %s file failed : %s at line %d, column %d", @@ -1480,15 +1483,15 @@ void OGRXLSXDataSource::AnalyseWorkbookRels(VSILFILE *fpWorkbookRels) nWithoutEventCounter = 0; nDataHandlerCounter = 0; - char aBuf[BUFSIZ]; + std::vector aBuf(PARSER_BUF_SIZE); int nDone = 0; do { nDataHandlerCounter = 0; - unsigned int nLen = - (unsigned int)VSIFReadL(aBuf, 1, sizeof(aBuf), fpWorkbookRels); + unsigned int nLen = (unsigned int)VSIFReadL(aBuf.data(), 1, aBuf.size(), + fpWorkbookRels); nDone = VSIFEofL(fpWorkbookRels); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { CPLError(CE_Failure, CPLE_AppDefined, "XML parsing of %s file failed : %s at line %d, column %d", @@ -1595,15 +1598,15 @@ void OGRXLSXDataSource::AnalyseWorkbook(VSILFILE *fpWorkbook) nWithoutEventCounter = 0; nDataHandlerCounter = 0; - char aBuf[BUFSIZ]; + std::vector aBuf(PARSER_BUF_SIZE); int nDone = 0; do { nDataHandlerCounter = 0; unsigned int nLen = - (unsigned int)VSIFReadL(aBuf, 1, sizeof(aBuf), fpWorkbook); + (unsigned int)VSIFReadL(aBuf.data(), 1, aBuf.size(), fpWorkbook); nDone = VSIFEofL(fpWorkbook); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { CPLError(CE_Failure, CPLE_AppDefined, "XML parsing of %s file failed : %s at line %d, column %d", @@ -1759,15 +1762,15 @@ void OGRXLSXDataSource::AnalyseStyles(VSILFILE *fpStyles) nDataHandlerCounter = 0; bInCellXFS = false; - char aBuf[BUFSIZ]; + std::vector aBuf(PARSER_BUF_SIZE); int nDone = 0; do { nDataHandlerCounter = 0; unsigned int nLen = - (unsigned int)VSIFReadL(aBuf, 1, sizeof(aBuf), fpStyles); + (unsigned int)VSIFReadL(aBuf.data(), 1, aBuf.size(), fpStyles); nDone = VSIFEofL(fpStyles); - if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR) + if (XML_Parse(oParser, aBuf.data(), nLen, nDone) == XML_STATUS_ERROR) { CPLError(CE_Failure, CPLE_AppDefined, "XML parsing of %s file failed : %s at line %d, column %d",