Repository navigation
fix(dwg): preserve MTEXT caret-adjacent whitespace (#2250) - #2314
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
DWG-to-DXF MTEXT rewrite crates/dwg/src/lib.rs |
The conversion output rewrites affected MTEXT content while preserving other DXF groups and embedded-object data. Text is encoded for legacy versions and chunked within group limits. Tests cover serialization, preservation of surrounding records, and output-limit errors. |
DXF round-trip coverage crates/io/tests/it/main.rs, crates/io/tests/it/mtext_caret_spaces.rs |
Fixtures and DXF tests check exact MTEXT contents across supported versions, text and binary formats, and repeated save/read passes. |
DWG round-trip and bridge coverage crates/io/tests/it/mtext_caret_spaces.rs |
DWG tests check native stored text, DWG-to-DXF conversion, and DWG read-back. Bridge tests check caret-adjacent whitespace in DXF wire text and parsed output. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Low
Suggested reviewers: vangel76
Merge Risk: 
Minimal · up to dfcbc
-
The MTEXT preservation change is mergeable after normal build and test checks; no specific regression was established.
Security architecture risk: 
Moderate · up to dfcbc
-
Large DWG files can now require both the original and rewritten DXF output in memory at once. That could exhaust a process even when each output stays within its size limit. The change does not add a public endpoint or grant new permissions.
Retained concerns
- Medium · security · inferred: A DWG containing selected MTEXT can make the conversion retain its original, near-limit DXF buffer while constructing another near-limit buffer, increasing process-exhaustion risk on the existing file-read path.
Security review details
-
Security Blast Radius
- inferred — A caller that opens an attacker-supplied DWG through the existing IO read function can reach the new allocation path. The evidence establishes process-level resource exposure, not tenant or service-wide reachability.
Security Findings and Attack Paths
- inferred — A sufficiently large accepted drawing with at least one selected MTEXT value can cause the bridge to retain the first DXF buffer while allocating a replacement. Whether that exhausts a particular process depends on its available memory.
Trust Boundaries and Controls
- observed — DWG bytes enter a failsafe third-party reader, then the rewritten DXF enters the repository's DXF parser. The size checks and error return limit individual outputs; the rewrite does not publish partial output after an error.
Resilience and Maintainability Implications
- inferred — The rewrite uses conversion-local state and returns an error on incomplete DXF pairs or capped writes; there is no new persistent state to recover. Those error paths do not address exhaustion while both buffers are live.
Hardening Proposals
- proposed — Bound aggregate conversion memory, for example by avoiding a simultaneous full-size source and destination DXF buffer or by applying a process memory budget where untrusted drawings are opened.
Pre-merge checks: 
3 · 
2
-
Failed checks: 2 warnings Passed checks: 3 passed-
Full details: Out of Scope Changes check
-
Explanation
The changed DWG bridge code, test registration, and regression tests support
#2250. The bridge limits replacement to MTEXT content groups and preserves embedded-object and unrelated records. No unrelated feature, dependency, tolerance, normalization, or format-marker change is shown.
-
Full details: Linked Issues check
-
Explanation
The implementation and default-enabled tests target
#2250.mtext_contentsreplaces only MTEXT group 1/3 contents before group 101 and usesDxfTextWriter::write_xrecord_string; the tests cover literal carets, whitespace, controls, chunking, versions, and two passes. However,#2250requires the listed automated checks and the applicable neighboring preservation matrix to pass. The PR states that no Cargo tests were run, and theroundtrip::dwg::extended::mtext_caretsregression from#2237is absent from this branch. The required runtime verification is therefore incomplete.Resolution
Run the listed focused tests and the applicable neighboring preservation families across the required save-version and encoding domains. Enable and run the corresponding
mtext_caretsregression when its test source is available. Record the passing results and link the resolution to#2238A12.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 8 functions across 3 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
austin62jake
left a comment
There was a problem hiding this comment.
Tested on Windows 10 Pro x64 (Rust 1.99.1, cargo-nextest 0.9.150), with this PR merged onto current main (336243e). It merges cleanly, and it works. The description says some checkpoints were traced in source, not run, so here they are run:
dwg_mtext_caret_spaces_round_tripfails onmainand passes with the fix.bridge_caret_space_is_escaped_once_in_each_direction,dxf_mtext_caret_spaces_round_tripand the existingparagraph_codes_tabs_and_carets_round_trippass.cargo xtask cipasses all 7 steps (2621 tests) with this PR merged ontomaintogether with #2294, #2287, #2301 and #2335, which I tested at the same time, and #2198 so the gate runs on Windows.
With cadcraft-cli, I saved two MTEXTs as DWG 2004 and DWG 2018 and reopened them:
| Text | main |
This PR |
|---|---|---|
^ C, a^b, x ^ y |
^C, a^b, x ^ y |
unchanged |
80 × é^ C (480 characters, so several group 3 chunks, and a code page in 2004) |
400 characters (every ^ lost its space) |
unchanged |
So the chunking keeps escape pairs together and the legacy code-page path works. The rewrite is limited to MTEXT records whose contents hold ^, a tab or a line feed, and it re-writes through the same CappedWriter, so the size cap still applies.
|
Tested with synthetic drawings made by CADCraft, checked in AutoCAD 2023. A DWG opened and saved twice by 0.14.0 really loses the spaces in AutoCAD ( |
FredApps
left a comment
There was a problem hiding this comment.
ReviewerA — source-read COMMENT (not an approval)
I read the first hunk: the DWG to DXF conversion runs the DXF writer and then a new mtext_contents(&doc, &mut out) step inside the same catch_unwind, and per the title (#2250) MTEXT whitespace next to a caret is preserved (a ^ followed by a space is the DXF escape for a literal caret-space, and a trimmed space changed the text). Preserving whitespace is right, since text content shouldn't be altered by a converter. Two points: the closure now returns a Result from write_to_writer(...)? so check that a writer error is reported as before (not as a panic message), and that the second pass can't double-write the text. I did not read mtext_contents. Add a round trip for A^ B, trailing spaces, tabs and a caret at the end. Nothing was run.
I ran nothing and have no exact-head CI result for this PR, so this is not an approval. Where a diff was long I read its code hunks rather than every generated or documentation line.
Status: waiting_author.
Problem
An authored MTEXT string
^ Creopens from DWG as^C(#2238 A12).Root cause
Source tracing of the pinned acadrust 0.6.6 bridge identifies an asymmetric return conversion, rather than an extra caret decode in the native DWG reader:
MText.contents^ C^ C(escape separator plus authored space)^ C^ C^ C^CThese checkpoints were traced in source, not executed locally. The new tests assert the native values and both conversion directions.
acadrust's ASCII reader decodes the bridge's caret escapes. Its ASCII writer treats a caret already followed by a space as escaped, so it does not add an independent separator for that literal space. CADCraft's existing MTEXT decoder correctly consumes the separator, exposing the missing escape. The return MTEXT writer also converts actual line feeds into paragraph codes.
Conversion boundary and changes
cadcraft-dwg's DWG-to-DXF return path, serialize affected MTEXT group 1/3 contents from the native model by handle, using acadrust's existingDxfTextWriter::write_xrecord_stringAPI for caret, tab and line-feed escaping.Regression coverage
Added default-enabled synthetic tests, not executed locally:
^ C,A ^ C B, repeated/trailing spaces, consecutive carets, literal^I/^J, real tabs and line feeds, adjacent\\P, stacked text and chunked contents.read()checks. Native inspection uses the same acadrust codec; this is not independent-codec interoperability evidence.Compatibility
The repair is limited to MTEXT content serialization on the DWG return bridge. It preserves literal carets separately from their following spaces and leaves ordinary DXF
^,^Iand^Jdecoding in its existing layer. Actual tabs/line feeds and existing paragraph formatting remain distinct.Excluded: #2251 Unicode/MIF double decoding, #2247 group-48 scoping (PR #2276 is not included), #2248 static-column loss, broader #532 work, and other #2238 findings.
Verification
git diff --check, staged diff check,git show --check, strict UTF-8 text inspection and full diff review.Focused checks for CI/maintainers (not run here):
Related
Fixes #2250. Related: #2238 A12 and #2237.
At review time #2237 is still open, at
ed37a1c8f83d7d995afacc4ace6dae32dd1f9483. Itsroundtrip::dwg::extended::mtext_caretsremains ignored and is absent from this branch's test tree. This PR neither cherry-picks its matrix nor changes that PR. Once the matrix is available with this fix, review/remove the corresponding ignore and run that family plus neighboring preservation families across their applicable save-version/encoding domains. Only in that environment is the following exact command applicable:Prepared with AI assistance for @Zaxaerith.
Summary by CodeRabbit