Skip to content

Commit

Permalink
DXF: do not error out on INSERT blocks with row count or column count…
Browse files Browse the repository at this point in the history
… equal to 0

Fixes #11591
  • Loading branch information
rouault committed Jan 17, 2025
1 parent f41af17 commit 8221e12
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 2 deletions.
200 changes: 200 additions & 0 deletions autotest/ogr/data/dxf/insert_only_col_count_zero.dxf
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
0
SECTION
2
TABLES
0
ENDSEC
0
SECTION
2
BLOCKS
0
BLOCK
5
44
100
AcDbEntity
8
0
100
AcDbBlockBegin
2
STAR
70
0
10
0.0
20
0.0
30
0.0
3
STAR
1

0
LINE
5
45
100
AcDbEntity
8
0
62
256
100
AcDbLine
10
-0.0281474976710656
20
1.0414574138294284
30
0.0
11
0.6192449487634439
21
-1.0696049115004942
31
0.0
0
LINE
5
46
100
AcDbEntity
8
0
62
256
100
AcDbLine
10
0.6192449487634439
20
-1.0696049115004942
30
0.0
11
-0.9570149208162315
21
0.4785074604081158
31
0.0
0
LINE
5
47
100
AcDbEntity
8
0
62
256
100
AcDbLine
10
-0.9570149208162315
20
0.4785074604081158
30
0.0
11
1.0414574138294284
21
0.3659174697238533
31
0.0
0
LINE
5
48
100
AcDbEntity
8
0
62
256
100
AcDbLine
10
1.0414574138294284
20
0.3659174697238533
30
0.0
11
-0.4785074604081158
21
-1.0414574138294284
31
0.0
0
LINE
5
49
100
AcDbEntity
8
0
62
256
100
AcDbLine
10
-0.4785074604081158
20
-1.0414574138294284
30
0.0
11
-0.0562949953421313
21
1.0133099161583627
31
0.0
0
ENDBLK
5
4A
100
AcDbEntity
8
0
100
AcDbBlockEnd
0
ENDSEC
0
SECTION
2
ENTITIES
0
INSERT
5
55
100
AcDbEntity
8
0
62
256
100
AcDbBlockReference
2
STAR
10
79.0976537766561876
20
119.9621950624433424
30
0.0
44
1.0
45
1.0
70
0
0
ENDSEC
0
EOF
21 changes: 21 additions & 0 deletions autotest/ogr/ogr_dxf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4124,3 +4124,24 @@ def test_ogr_dxf_write_MEASUREMENT(tmp_vsimem):
pass
with ogr.Open(filename) as ds:
assert ds.GetMetadataItem("$MEASUREMENT", "DXF_HEADER_VARIABLES") == " 0"


###############################################################################
# Use case of https://github.com/OSGeo/gdal/issues/11591
# Test reading a INSERT block whose column count is zero.
# Not totally sure about the exact behavior we should do. Currently
# the zero count is strictly honored and no geometry from the block will be
# inserted into the regular geometries. LibreCAD 2.1.3 does the same thing


@gdaltest.enable_exceptions()
def test_ogr_dxf_insert_col_count_zero():

with ogr.Open("data/dxf/insert_only_col_count_zero.dxf") as ds:
lyr = ds.GetLayer(0)
assert lyr.GetFeatureCount() == 0

with gdal.config_option("DXF_INLINE_BLOCKS", "NO"):
with ogr.Open("data/dxf/insert_only_col_count_zero.dxf") as ds:
lyr = ds.GetLayerByName("blocks")
assert lyr.GetFeatureCount() == 1
2 changes: 2 additions & 0 deletions ogr/ogrsf_frmts/dxf/ogrdxfdatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ int OGRDXFDataSource::Open(const char *pszFilename, bool bHeaderOnly,
CSLConstList papszOptionsIn)

{
SetDescription(pszFilename);

osEncoding = CPL_ENC_ISO8859_1;

bInlineBlocks = CPLTestBool(
Expand Down
10 changes: 8 additions & 2 deletions ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3167,7 +3167,7 @@ bool OGRDXFLayer::TranslateINSERT()

case 70:
m_oInsertState.m_nColumnCount = atoi(szLineBuf);
if (m_oInsertState.m_nColumnCount <= 0)
if (m_oInsertState.m_nColumnCount < 0)
{
DXF_LAYER_READER_ERROR();
m_oInsertState.m_nRowCount = 0;
Expand All @@ -3178,7 +3178,7 @@ bool OGRDXFLayer::TranslateINSERT()

case 71:
m_oInsertState.m_nRowCount = atoi(szLineBuf);
if (m_oInsertState.m_nRowCount <= 0)
if (m_oInsertState.m_nRowCount < 0)
{
DXF_LAYER_READER_ERROR();
m_oInsertState.m_nRowCount = 0;
Expand All @@ -3205,6 +3205,12 @@ bool OGRDXFLayer::TranslateINSERT()
return false;
}

if (m_oInsertState.m_nRowCount == 0 || m_oInsertState.m_nColumnCount == 0)
{
m_oInsertState.m_nRowCount = 0;
m_oInsertState.m_nColumnCount = 0;
}

/* -------------------------------------------------------------------- */
/* Process any attribute entities. */
/* -------------------------------------------------------------------- */
Expand Down

0 comments on commit 8221e12

Please sign in to comment.