Opened 15 years ago
Closed 15 years ago
#2727 closed defect (fixed)
ogrinfo returns 'Corrupt data' error for wkt of length 1023 characters
Reported by: | amayuk | Owned by: | chaitanya |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | OGR_SF | Version: | 1.5.3 |
Severity: | normal | Keywords: | odbc |
Cc: | warmerdam, chaitanya |
Description (last modified by )
ogrinfo returns 'Error 1: GetNextRawFeatures(): Corrupt data' when used with a wkt feature which is of length 1023 characters.
This was seen with data in a SQL server 2008 express database. To create a table and populate it with test data run the following script:
CREATE TABLE [dbo].[snhd_wkt2]( [ID] [int] NULL, [XMIN] [float] NULL, [YMIN] [float] NULL, [XMAX] [float] NULL, [YMAX] [float] NULL, [WKT] [varchar](max) NULL ) ON [PRIMARY] INSERT INTO [dbo].[snhd_wkt2] VALUES ('1', '424137.474088898', '140734.844325094', '424381.173359863', '140870.555478181', 'Polygon ((424141.423 140736.164,424141.415 140736.164,424141.432 140736.174,424141.860 140736.574,424142.512 140737.224,424143.353 140738.223,424144.103 140739.283,424144.787 140740.403,424145.356 140741.582,424145.851 140742.792,424146.230 140744.052,424146.544 140745.311,424146.692 140746.611,424146.791 140747.921,424146.758 140749.230,424146.634 140750.530,424146.387 140751.829,424146.041 140753.089,424145.604 140754.309,424145.480 140754.589,424144.870 140755.568,424144.120 140757.328,424143.246 140759.127,424140.929 140763.916,424137.474 140770.954,424158.928 140773.253,424179.037 140778.462,424194.835 140782.231,424243.481 140812.932,424280.105 140836.445,424296.257 140847.032,424330.903 140864.627,424359.448 140870.555,424372.013 140868.036,424379.195 140862.118,424381.173 140848.472,424374.528 140833.036,424356.397 140826.748,424323.004 140824.059,424266.460 140798.386,424235.945 140782.051,424209.016 140767.695,424196.088 140751.180,424173.472 140739.683,424151.573 140734.844,424141.423 140736.164))')
Create an ODBC connection (in this case called 'SpatialTest' to the SQL Server database and run the following ogrinfo command (in this case with a user/password both of 'test'):
ogrinfo -ro -so "ODBC:test/test@spatialtest" snhd_wkt2
The following is returned:
ERROR 1: Column Geometry requested for geometry, but it does not exist. INFO: Open of `ODBC:test/test@spatialtest' using driver `ODBC' successful. Layer name: SNHD_wkt2 Geometry: Unknown (any) ERROR 1: GetNextRawFeature(): Corrupt data Feature Count: 1 ERROR 1: GetNextRawFeature(): Corrupt data Layer SRS WKT: (unknown) ID: Integer (10.0) XMIN: Real (0.0) YMIN: Real (0.0) XMAX: Real (0.0) YMAX: Real (0.0)
If a blank character is entered into the WKT string (i.e. making is longer than 1023 characters) then ogrinfo works without any errors.
Change History (14)
comment:1 by , 15 years ago
Component: | default → OGR_SF |
---|---|
Description: | modified (diff) |
Keywords: | odbc added |
Status: | new → assigned |
comment:2 by , 15 years ago
Version: | unspecified → 1.5.3 |
---|
comment:3 by , 15 years ago
Cc: | added |
---|---|
Owner: | changed from | to
Status: | assigned → new |
Roni,
Please make sure you note anything of significance that you learn about this problem.
comment:4 by , 15 years ago
Chaitanya,
Please attempt to reproduce this problem on SQL Server Express as time permits. It is low priority.
comment:5 by , 15 years ago
I need all the table names and field names of that database. I am close to this bug. But this can occur only in special situation of database table.
comment:6 by , 15 years ago
There is just one table in the database. The fields are described above.
comment:7 by , 15 years ago
You have tried to create a database with 6 column but in the ogrinfo output this is looking like 5 column. Is it a copy error else you got right this output from ogrinfo?
comment:8 by , 15 years ago
Yes, that's the correct output.
Further investigation shows this error occurs for wkt of length (x*511)+1, where x>1.
follow-up: 10 comment:9 by , 15 years ago
Yes, for a WKT of length x*511+1, cpl_odbc will fail to trim a '\0' before appending the last char ")". ogr2ogr also reports the same error.
Code: int CPLODBCStatement::Fetch( int nOrientation, int nOffset )
{ ...
if( cbDataLen > (int) (sizeof(szWrkData) - 1)
cbDataLen == SQL_NO_TOTAL ) {
nChunkLen = sizeof(szWrkData)-1; if (nFetchType == SQL_C_CHAR)
while ( (nChunkLen > 1)
&& (szWrkData[nChunkLen - 1] == 0) )
--nChunkLen; trimming the extra terminators
} else
nChunkLen = cbDataLen;
}
In the second to the last reading, cbDataLen = 512, sizeof(szWrkData)=512, so we skip the trimming. In the reading cbDatalen =1, and the char is ")". For example, a DBS WKT "POLYGON(('......'))" will becomes "POLYGON(('......')\0)" so 'Corrupt data'
comment:10 by , 15 years ago
Replying to lgao: oops, I meant sizeof(szWrkData)-1 = 512, so we skip the trimming...
comment:11 by , 15 years ago
Cc: | added |
---|
Ashraf,
Do you have time to follow up on this? Or should I move it to Chaitanya?
comment:12 by , 15 years ago
Frank, I am busy with opengraphrouter in GSoC can you please send this bug to Chaitanya. After this month I will be available from 1st July. If you allow me that time definitely I will solve this.
comment:13 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:14 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Hi, could you add a note (or set the version flag for this ticket) indicating what version of GDAL/OGR you are using? This sounds a bit like bug #990.