2081 {
2082 int32 nPoints, nParts;
2083 int i, nOffset;
2086
2088 {
2089 snprintf(szErrorMsg, sizeof(szErrorMsg),
2090 "Corrupted .shp file : shape %d : nEntitySize = %d",
2092 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
2093 psSHP->sHooks.Error( szErrorMsg );
2096 }
2097
2098
2099
2100 memcpy( &(
psShape->dfXMin), psSHP->pabyRec + 8 + 4, 8 );
2101 memcpy( &(
psShape->dfYMin), psSHP->pabyRec + 8 + 12, 8 );
2102 memcpy( &(
psShape->dfXMax), psSHP->pabyRec + 8 + 20, 8 );
2103 memcpy( &(
psShape->dfYMax), psSHP->pabyRec + 8 + 28, 8 );
2104
2109
2110
2111
2112
2113
2114 memcpy( &nPoints, psSHP->pabyRec + 40 + 8, 4 );
2115 memcpy( &nParts, psSHP->pabyRec + 36 + 8, 4 );
2116
2119
2120
2121 if (
2122 nPoints > 50 * 1000 * 1000 || nParts > 10 * 1000 * 1000)
2123 {
2124 snprintf(szErrorMsg, sizeof(szErrorMsg),
2125 "Corrupted .shp file : shape %d, nPoints=%u, nParts=%u.",
2126 hEntity, nPoints, nParts);
2127 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
2128 psSHP->sHooks.Error( szErrorMsg );
2131 }
2132
2133
2134
2135
2136 nRequiredSize = 44 + 8 + 4 * nParts + 16 * nPoints;
2140 {
2141 nRequiredSize += 16 + 8 * nPoints;
2142 }
2144 {
2145 nRequiredSize += 4 * nParts;
2146 }
2148 {
2149 snprintf(szErrorMsg, sizeof(szErrorMsg),
2150 "Corrupted .shp file : shape %d, nPoints=%u, nParts=%u, nEntitySize=%d.",
2152 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
2153 psSHP->sHooks.Error( szErrorMsg );
2156 }
2157
2158 if(
psShape->bFastModeReadObject )
2159 {
2160 int nObjectBufSize = 4 * sizeof(double) * nPoints + 2 * sizeof(int) * nParts;
2162 ppBuffer = &pBuffer;
2163 }
2164
2170
2174
2181 {
2182 snprintf(szErrorMsg, sizeof(szErrorMsg),
2183 "Not enough memory to allocate requested memory (nPoints=%u, nParts=%u) for shape %d. "
2184 "Probably broken SHP file", nPoints, nParts, hEntity );
2185 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
2186 psSHP->sHooks.Error( szErrorMsg );
2189 }
2190
2193
2194
2195
2196
2197 memcpy(
psShape->panPartStart, psSHP->pabyRec + 44 + 8, 4 * nParts );
2199 {
2201
2202
2203 if (
psShape->panPartStart[i] < 0
2207 {
2208 snprintf(szErrorMsg, sizeof(szErrorMsg),
2209 "Corrupted .shp file : shape %d : panPartStart[%d] = %d, nVertices = %d",
2211 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
2212 psSHP->sHooks.Error( szErrorMsg );
2215 }
2216 if (i > 0 &&
psShape->panPartStart[i] <=
psShape->panPartStart[i-1])
2217 {
2218 snprintf(szErrorMsg, sizeof(szErrorMsg),
2219 "Corrupted .shp file : shape %d : panPartStart[%d] = %d, panPartStart[%d] = %d",
2220 hEntity, i,
psShape->panPartStart[i], i - 1,
psShape->panPartStart[i - 1]);
2221 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
2222 psSHP->sHooks.Error( szErrorMsg );
2225 }
2226 }
2227
2228 nOffset = 44 + 8 + 4*nParts;
2229
2230
2231
2232
2234 {
2235 memcpy(
psShape->panPartType, psSHP->pabyRec + nOffset, 4*nParts );
2237 {
2239 }
2240
2241 nOffset += 4*nParts;
2242 }
2243
2244
2245
2246
2248 {
2250 psSHP->pabyRec + nOffset + i * 16,
2251 8 );
2252
2254 psSHP->pabyRec + nOffset + i * 16 + 8,
2255 8 );
2256
2259 }
2260
2261 nOffset += 16*nPoints;
2262
2263
2264
2265
2269 {
2270 memcpy( &(
psShape->dfZMin), psSHP->pabyRec + nOffset, 8 );
2271 memcpy( &(
psShape->dfZMax), psSHP->pabyRec + nOffset + 8, 8 );
2272
2275
2277 {
2279 psSHP->pabyRec + nOffset + 16 + i*8, 8 );
2281 }
2282
2283 nOffset += 16 + 8*nPoints;
2284 }
2285 else if(
psShape->bFastModeReadObject )
2286 {
2288 }
2289
2290
2291
2292
2293
2294
2295
2297 {
2298 memcpy( &(
psShape->dfMMin), psSHP->pabyRec + nOffset, 8 );
2299 memcpy( &(
psShape->dfMMax), psSHP->pabyRec + nOffset + 8, 8 );
2300
2303
2305 {
2307 psSHP->pabyRec + nOffset + 16 + i*8, 8 );
2309 }
2311 }
2312 else if(
psShape->bFastModeReadObject )
2313 {
2315 }
2316 }
static void SwapWord(int length, void *wordP)
static unsigned char * SHPReallocObjectBufIfNecessary(SHPHandle psSHP, int nObjectBufSize)
#define STATIC_CAST(type, x)
void SHPAPI_CALL SHPDestroyObject(SHPObject *psShape)
static void * SHPAllocBuffer(unsigned char **pBuffer, int nSize)