Skip to content

Commit

Permalink
decode_r11: fix wrong ltype size for POLYLINE/VERTEX
Browse files Browse the repository at this point in the history
Fixes GH #832
  • Loading branch information
rurban committed Sep 4, 2023
1 parent 088dcf0 commit 524364b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
32 changes: 22 additions & 10 deletions src/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -6488,6 +6488,7 @@ decode_preR13_entities (BITCODE_RL start, BITCODE_RL end,
{
Dwg_Object *obj;
Dwg_Object_Type_r11 abstype;
BITCODE_RC pline_flag;

if (!num)
dwg->object
Expand Down Expand Up @@ -6687,7 +6688,6 @@ decode_preR13_entities (BITCODE_RL start, BITCODE_RL end,
BITCODE_RC extra_r11 = 0;
BITCODE_RS eed_size;
BITCODE_RC handling_len;
BITCODE_RC pline_flag;
size_t start_byte;
LOG_TRACE ("Detect polyline:");
start_byte = dat->byte;
Expand All @@ -6707,12 +6707,17 @@ decode_preR13_entities (BITCODE_RL start, BITCODE_RL end,
if (flag_r11 & FLAG_R11_HAS_COLOR)
dat->byte += 1;
if (flag_r11 & FLAG_R11_HAS_LTYPE)
dat->byte += 2;
{
PRE (R_11)
dat->byte += 1;
else
dat->byte += 2;
}
if (flag_r11 & FLAG_R11_HAS_THICKNESS)
dat->byte += 8;
if (flag_r11 & FLAG_R11_HAS_ELEVATION)
dat->byte += 8;
if (extra_r11 && extra_r11 & EXTRA_R11_HAS_EED)
if (extra_r11 & EXTRA_R11_HAS_EED)
{
eed_size = bit_read_RS (dat);
LOG_TRACE (", eed_size: %d", eed_size);
Expand All @@ -6724,10 +6729,11 @@ decode_preR13_entities (BITCODE_RL start, BITCODE_RL end,
LOG_TRACE (", handling_len: %d", handling_len);
dat->byte += handling_len;
}
if (extra_r11 && extra_r11 & EXTRA_R11_HAS_VIEWPORT)
if (extra_r11 & EXTRA_R11_HAS_VIEWPORT)
dat->byte += 2;
pline_flag = bit_read_RC (dat);
LOG_TRACE (", pline_flag: 0x%x\n", pline_flag);
LOG_TRACE (", pline_flag: 0x%x", pline_flag);
LOG_POS;
dat->byte = start_byte;
if (pline_flag & FLAG_POLYLINE_3D)
error |= dwg_decode_POLYLINE_3D (dat, obj);
Expand Down Expand Up @@ -6766,7 +6772,12 @@ decode_preR13_entities (BITCODE_RL start, BITCODE_RL end,
if (flag_r11 & FLAG_R11_HAS_COLOR)
dat->byte += 1;
if (flag_r11 & FLAG_R11_HAS_LTYPE)
dat->byte += 2;
{
PRE (R_11)
dat->byte += 1;
else
dat->byte += 2;
}
if (flag_r11 & FLAG_R11_HAS_THICKNESS)
dat->byte += 8;
if (flag_r11 & FLAG_R11_HAS_ELEVATION)
Expand Down Expand Up @@ -6801,17 +6812,18 @@ decode_preR13_entities (BITCODE_RL start, BITCODE_RL end,
if (opts_r11 & OPTS_R11_VERTEX_HAS_FLAG)
{
vertex_flag = bit_read_RC (dat);
LOG_TRACE (", vertex_flag: 0x%x\n", vertex_flag);
LOG_TRACE (", vertex_flag: 0x%x", vertex_flag);
LOG_POS;
dat->byte = start_byte;
if (vertex_flag & FLAG_VERTEX_3D)
error |= dwg_decode_VERTEX_3D (dat, obj);
else if (vertex_flag & FLAG_VERTEX_MESH
if (vertex_flag & FLAG_VERTEX_MESH
&& vertex_flag & FLAG_VERTEX_PFACE_MESH)
error |= dwg_decode_VERTEX_PFACE (dat, obj);
else if (vertex_flag & FLAG_VERTEX_MESH)
error |= dwg_decode_VERTEX_MESH (dat, obj);
else if (vertex_flag & FLAG_VERTEX_PFACE_MESH)
error |= dwg_decode_VERTEX_PFACE_FACE (dat, obj);
else if (vertex_flag & FLAG_VERTEX_3D)
error |= dwg_decode_VERTEX_3D (dat, obj);
else
error |= dwg_decode_VERTEX_2D (dat, obj);
}
Expand Down
3 changes: 2 additions & 1 deletion src/decode_r11.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ decode_preR13_section_hdr (const char *restrict name, Dwg_Section_Type_r11 id,
LOG_ERROR ("%s.size overflow %zu > %zu", tbl->name,
(size_t)(tbl->address + (tbl->number * tbl->size)),
dat->size);
return DWG_ERR_INVALIDDWG;
// VPORT.size bug in DWG, ignore it.
return id == SECTION_VPORT ? 0 : 1;
}
return 0;
}
Expand Down
6 changes: 4 additions & 2 deletions src/dwg.spec
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,10 @@ DWG_ENTITY (VERTEX_3D)
PRE (R_13b1)
{
FIELD_2RD (point, 10);
FIELD_RC (flag, 0);
LOG_FLAG_VERTEX
if (R11OPTS (8)) {
FIELD_RC (flag, 0);
LOG_FLAG_VERTEX
}
}
LATER_VERSIONS {
FIELD_RC (flag, 0);
Expand Down

0 comments on commit 524364b

Please sign in to comment.