2070 {
2071 int32 nPoints, nParts;
2072 int i, nOffset;
2075
2077 {
2078 snprintf(szErrorMsg, sizeof(szErrorMsg),
2079 "Corrupted .shp file : shape %d : nEntitySize = %d",
2081 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
2082 psSHP->sHooks.Error( szErrorMsg );
2085 }
2086
2087
2088
2089 memcpy( &(
psShape->dfXMin), psSHP->pabyRec + 8 + 4, 8 );
2090 memcpy( &(
psShape->dfYMin), psSHP->pabyRec + 8 + 12, 8 );
2091 memcpy( &(
psShape->dfXMax), psSHP->pabyRec + 8 + 20, 8 );
2092 memcpy( &(
psShape->dfYMax), psSHP->pabyRec + 8 + 28, 8 );
2093
2098
2099
2100
2101
2102
2103 memcpy( &nPoints, psSHP->pabyRec + 40 + 8, 4 );
2104 memcpy( &nParts, psSHP->pabyRec + 36 + 8, 4 );
2105
2108
2109
2110 if (
2111 nPoints > 50 * 1000 * 1000 || nParts > 10 * 1000 * 1000)
2112 {
2113 snprintf(szErrorMsg, sizeof(szErrorMsg),
2114 "Corrupted .shp file : shape %d, nPoints=%u, nParts=%u.",
2115 hEntity, nPoints, nParts);
2116 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
2117 psSHP->sHooks.Error( szErrorMsg );
2120 }
2121
2122
2123
2124
2125 nRequiredSize = 44 + 8 + 4 * nParts + 16 * nPoints;
2129 {
2130 nRequiredSize += 16 + 8 * nPoints;
2131 }
2133 {
2134 nRequiredSize += 4 * nParts;
2135 }
2137 {
2138 snprintf(szErrorMsg, sizeof(szErrorMsg),
2139 "Corrupted .shp file : shape %d, nPoints=%u, nParts=%u, nEntitySize=%d.",
2141 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
2142 psSHP->sHooks.Error( szErrorMsg );
2145 }
2146
2147 if(
psShape->bFastModeReadObject )
2148 {
2149 int nObjectBufSize = 4 * sizeof(double) * nPoints + 2 * sizeof(int) * nParts;
2151 ppBuffer = &pBuffer;
2152 }
2153
2159
2163
2170 {
2171 snprintf(szErrorMsg, sizeof(szErrorMsg),
2172 "Not enough memory to allocate requested memory (nPoints=%u, nParts=%u) for shape %d. "
2173 "Probably broken SHP file", nPoints, nParts, hEntity );
2174 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
2175 psSHP->sHooks.Error( szErrorMsg );
2178 }
2179
2182
2183
2184
2185
2186 memcpy(
psShape->panPartStart, psSHP->pabyRec + 44 + 8, 4 * nParts );
2188 {
2190
2191
2192 if (
psShape->panPartStart[i] < 0
2196 {
2197 snprintf(szErrorMsg, sizeof(szErrorMsg),
2198 "Corrupted .shp file : shape %d : panPartStart[%d] = %d, nVertices = %d",
2200 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
2201 psSHP->sHooks.Error( szErrorMsg );
2204 }
2205 if (i > 0 &&
psShape->panPartStart[i] <=
psShape->panPartStart[i-1])
2206 {
2207 snprintf(szErrorMsg, sizeof(szErrorMsg),
2208 "Corrupted .shp file : shape %d : panPartStart[%d] = %d, panPartStart[%d] = %d",
2209 hEntity, i,
psShape->panPartStart[i], i - 1,
psShape->panPartStart[i - 1]);
2210 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
2211 psSHP->sHooks.Error( szErrorMsg );
2214 }
2215 }
2216
2217 nOffset = 44 + 8 + 4*nParts;
2218
2219
2220
2221
2223 {
2224 memcpy(
psShape->panPartType, psSHP->pabyRec + nOffset, 4*nParts );
2226 {
2228 }
2229
2230 nOffset += 4*nParts;
2231 }
2232
2233
2234
2235
2237 {
2239 psSHP->pabyRec + nOffset + i * 16,
2240 8 );
2241
2243 psSHP->pabyRec + nOffset + i * 16 + 8,
2244 8 );
2245
2248 }
2249
2250 nOffset += 16*nPoints;
2251
2252
2253
2254
2258 {
2259 memcpy( &(
psShape->dfZMin), psSHP->pabyRec + nOffset, 8 );
2260 memcpy( &(
psShape->dfZMax), psSHP->pabyRec + nOffset + 8, 8 );
2261
2264
2266 {
2268 psSHP->pabyRec + nOffset + 16 + i*8, 8 );
2270 }
2271
2272 nOffset += 16 + 8*nPoints;
2273 }
2274 else if(
psShape->bFastModeReadObject )
2275 {
2277 }
2278
2279
2280
2281
2282
2283
2284
2286 {
2287 memcpy( &(
psShape->dfMMin), psSHP->pabyRec + nOffset, 8 );
2288 memcpy( &(
psShape->dfMMax), psSHP->pabyRec + nOffset + 8, 8 );
2289
2292
2294 {
2296 psSHP->pabyRec + nOffset + 16 + i*8, 8 );
2298 }
2300 }
2301 else if(
psShape->bFastModeReadObject )
2302 {
2304 }
2305 }
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)