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 OSGeo#11591
  • Loading branch information
rouault committed Jan 17, 2025
1 parent f41af17 commit 2b33952
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
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 2b33952

Please sign in to comment.