diff --git a/autotest/ogr/data/dxf/insert_only_col_count_zero.dxf b/autotest/ogr/data/dxf/insert_only_col_count_zero.dxf new file mode 100644 index 000000000000..04b8de6fda85 --- /dev/null +++ b/autotest/ogr/data/dxf/insert_only_col_count_zero.dxf @@ -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 diff --git a/autotest/ogr/ogr_dxf.py b/autotest/ogr/ogr_dxf.py index a7570c3fe3c0..93230b9da6bd 100644 --- a/autotest/ogr/ogr_dxf.py +++ b/autotest/ogr/ogr_dxf.py @@ -4021,3 +4021,22 @@ def test_ogr_dxf_read_closed_polyline_with_bulge(): f = lyr.GetNextFeature() g = f.GetGeometryRef() assert g.GetGeometryType() == ogr.wkbPolygon + + +############################################################################### +# Use case of https://github.com/OSGeo/gdal/issues/11591 +# Test reading a INSERT block whose column count is zero. +# Interpretating it as 1, as AutoCAD does + + +@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() == 1 + + 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 diff --git a/ogr/ogrsf_frmts/dxf/ogrdxfdatasource.cpp b/ogr/ogrsf_frmts/dxf/ogrdxfdatasource.cpp index 52a3dc74323c..6d53d137a18f 100644 --- a/ogr/ogrsf_frmts/dxf/ogrdxfdatasource.cpp +++ b/ogr/ogrsf_frmts/dxf/ogrdxfdatasource.cpp @@ -88,6 +88,8 @@ int OGRDXFDataSource::Open(const char *pszFilename, bool bHeaderOnly, CSLConstList papszOptionsIn) { + SetDescription(pszFilename); + osEncoding = CPL_ENC_ISO8859_1; bInlineBlocks = CPLTestBool( diff --git a/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp b/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp index 719d3bb85324..bc3e519499c2 100644 --- a/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp +++ b/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp @@ -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; @@ -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; @@ -3205,6 +3205,14 @@ bool OGRDXFLayer::TranslateINSERT() return false; } + if (m_oInsertState.m_nRowCount == 0 || m_oInsertState.m_nColumnCount == 0) + { + // AutoCad doesn't allow setting to 0 in its UI, but interprets 0 + // as 1 (but other software such as LibreCAD interpret 0 as 0) + m_oInsertState.m_nRowCount = 1; + m_oInsertState.m_nColumnCount = 1; + } + /* -------------------------------------------------------------------- */ /* Process any attribute entities. */ /* -------------------------------------------------------------------- */