Skip to content

Pre-R2007 strings are decoded as lossy UTF-8, not in the drawing's $DWGCODEPAGE #370

Closed

Description

@DrunkOnJava

Every pre-R2007 string the crate reads is decoded with String::from_utf8_lossy. A drawing from R2000 to R2004 stores its text in the code page named by $DWGCODEPAGE (ANSI_1252 in the corpus), so any byte above 0x7F that is not valid UTF-8 by itself becomes U+FFFD: a degree sign (0xB0) or an é (0xE9) is lost on the way in, and dxf_header::escape_text then writes \U+FFFD where AutoCAD's export writes \U+00B0.

Where it happens (17 call sites at the time of writing, found with grep -rn from_utf8_lossy src): tables::read_tv (every table entry name), the entity readers entities::text, attrib, attdef, mtext, tolerance, imagedef, block, the object readers through objects::modern::read_tv, and the linetype text area of a complex LTYPE (dxf_tables::dash_text, which matches the TV readers on purpose). The code page is read (header::CommonHeader::codepage, bytes 0x13 to 0x14) and dxf_header writes $DWGCODEPAGE from it, but nothing uses it to decode a string.

Proposed: one decoder for a pre-R2007 byte string, keyed by the drawing's code page (at least the Windows single-byte pages AutoCAD uses, ANSI_1250 to ANSI_1258, and the DBCS ones as raw bytes with a stated limit), used by every reader above instead of from_utf8_lossy; the string stream's TU reader (UTF-16) is not affected. Evidence to add with it: a corpus drawing with a non-ASCII legacy string, paired against AutoCAD's export (94\U+00B0 is in the R2000 export of sample_AC1015), through the existing probes.

Found while reviewing the linetype text of #358 (Codex's review of dash_text); not solved inside the DXF writer, so that linetype text, layer names and every other legacy string stay consistent with each other.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:string-streamtype:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions