1669 {
1670 int32 nPoints, nParts;
1672
1674 {
1675 snprintf(szErrorMsg, sizeof(szErrorMsg),
1676 "Corrupted .shp file : shape %d : nEntitySize = %d",
1678 psSHP->sHooks.Error( szErrorMsg );
1680 return NULL;
1681 }
1682
1683
1684
1685 memcpy( &(
psShape->dfXMin), psSHP->pabyRec + 8 + 4, 8 );
1686 memcpy( &(
psShape->dfYMin), psSHP->pabyRec + 8 + 12, 8 );
1687 memcpy( &(
psShape->dfXMax), psSHP->pabyRec + 8 + 20, 8 );
1688 memcpy( &(
psShape->dfYMax), psSHP->pabyRec + 8 + 28, 8 );
1689
1694
1695
1696
1697
1698
1699 memcpy( &nPoints, psSHP->pabyRec + 40 + 8, 4 );
1700 memcpy( &nParts, psSHP->pabyRec + 36 + 8, 4 );
1701
1704
1705 if (nPoints > 50 * 1000 * 1000 || nParts > 10 * 1000 * 1000)
1706 {
1707 snprintf(szErrorMsg, sizeof(szErrorMsg),
1708 "Corrupted .shp file : shape %d, nPoints=%d, nParts=%d.",
1709 hEntity, nPoints, nParts);
1710 psSHP->sHooks.Error( szErrorMsg );
1712 return NULL;
1713 }
1714
1715
1716
1717
1718 nRequiredSize = 44 + 8 + 4 * nParts + 16 * nPoints;
1722 {
1723 nRequiredSize += 16 + 8 * nPoints;
1724 }
1726 {
1727 nRequiredSize += 4 * nParts;
1728 }
1730 {
1731 snprintf(szErrorMsg, sizeof(szErrorMsg),
1732 "Corrupted .shp file : shape %d, nPoints=%d, nParts=%d, nEntitySize=%d.",
1734 psSHP->sHooks.Error( szErrorMsg );
1736 return NULL;
1737 }
1738
1740 psShape->padfX = (
double *) calloc(nPoints,
sizeof(
double));
1741 psShape->padfY = (
double *) calloc(nPoints,
sizeof(
double));
1742 psShape->padfZ = (
double *) calloc(nPoints,
sizeof(
double));
1743 psShape->padfM = (
double *) calloc(nPoints,
sizeof(
double));
1744
1746 psShape->panPartStart = (
int *) calloc(nParts,
sizeof(
int));
1747 psShape->panPartType = (
int *) calloc(nParts,
sizeof(
int));
1748
1753 psShape->panPartStart == NULL ||
1755 {
1756 snprintf(szErrorMsg, sizeof(szErrorMsg),
1757 "Not enough memory to allocate requested memory (nPoints=%d, nParts=%d) for shape %d. "
1758 "Probably broken SHP file", hEntity, nPoints, nParts );
1759 psSHP->sHooks.Error( szErrorMsg );
1761 return NULL;
1762 }
1763
1764 for( i = 0; i < nParts; i++ )
1766
1767
1768
1769
1770 memcpy(
psShape->panPartStart, psSHP->pabyRec + 44 + 8, 4 * nParts );
1771 for( i = 0; i < nParts; i++ )
1772 {
1774
1775
1776 if (
psShape->panPartStart[i] < 0
1779 {
1780 snprintf(szErrorMsg, sizeof(szErrorMsg),
1781 "Corrupted .shp file : shape %d : panPartStart[%d] = %d, nVertices = %d",
1783 psSHP->sHooks.Error( szErrorMsg );
1785 return NULL;
1786 }
1787 if (i > 0 &&
psShape->panPartStart[i] <=
psShape->panPartStart[i-1])
1788 {
1789 snprintf(szErrorMsg, sizeof(szErrorMsg),
1790 "Corrupted .shp file : shape %d : panPartStart[%d] = %d, panPartStart[%d] = %d",
1791 hEntity, i,
psShape->panPartStart[i], i - 1,
psShape->panPartStart[i - 1]);
1792 psSHP->sHooks.Error( szErrorMsg );
1794 return NULL;
1795 }
1796 }
1797
1798 nOffset = 44 + 8 + 4*nParts;
1799
1800
1801
1802
1804 {
1805 memcpy(
psShape->panPartType, psSHP->pabyRec + nOffset, 4*nParts );
1806 for( i = 0; i < nParts; i++ )
1807 {
1809 }
1810
1811 nOffset += 4*nParts;
1812 }
1813
1814
1815
1816
1817 for( i = 0; i < nPoints; i++ )
1818 {
1820 psSHP->pabyRec + nOffset + i * 16,
1821 8 );
1822
1824 psSHP->pabyRec + nOffset + i * 16 + 8,
1825 8 );
1826
1829 }
1830
1831 nOffset += 16*nPoints;
1832
1833
1834
1835
1839 {
1840 memcpy( &(
psShape->dfZMin), psSHP->pabyRec + nOffset, 8 );
1841 memcpy( &(
psShape->dfZMax), psSHP->pabyRec + nOffset + 8, 8 );
1842
1845
1846 for( i = 0; i < nPoints; i++ )
1847 {
1849 psSHP->pabyRec + nOffset + 16 + i*8, 8 );
1851 }
1852
1853 nOffset += 16 + 8*nPoints;
1854 }
1855
1856
1857
1858
1859
1860
1861
1863 {
1864 memcpy( &(
psShape->dfMMin), psSHP->pabyRec + nOffset, 8 );
1865 memcpy( &(
psShape->dfMMax), psSHP->pabyRec + nOffset + 8, 8 );
1866
1869
1870 for( i = 0; i < nPoints; i++ )
1871 {
1873 psSHP->pabyRec + nOffset + 16 + i*8, 8 );
1875 }
1877 }
1878 }
static void SwapWord(int length, void *wordP)
void SHPAPI_CALL SHPDestroyObject(SHPObject *psShape)