Skip to content

DXF: read up to 100 million group codes, or a set limit, without running out of memory silently (#1976) - #2683

Merged
tanish2k09 merged 4 commits into
mainfrom
land/1976
Nov 3, 2026
Merged

tanish2k09 merged 4 commits into
mainfrom
land/1976

Conversation

@tanish2k09

@tanish2k09 tanish2k09 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Builds on #1976 by @MrBeeboh and keeps those commits: the CADCRAFT_MAX_DXF_TAGS override, and a higher default.

What changed from #1976, after the memory objection that review raised:

  • 100 million by default, not 150 million. The file-size limits already bound memory: 512 MB for a DXF opened directly, and 1 GB for a DWG's DXF rendition. Within those, a crafted 512 MB file with the shortest possible pairs reaches about 4 GB of tags at 100 million, against about 6 GB at 150 million. 100 million still covers the 56-million-tag, 172 MB drawing in Raise DWG/DXF size limits so large drawings open #2427.
  • The tag list is reserved once, with an allocation that can fail. The ASCII parser already counts tags up front, so it now reserves exactly that many, and a refusal is a DxfError::OutOfMemory instead of the end of the app. Where the system enforces a commit limit, as Windows does, running out of memory for that list is now an error. Reserving once also avoids a vector doubling briefly taking half as much again. String values are still allocated as they are read, and Linux overcommit can still end the process later, so this narrows the risk rather than removing it.
  • The "too large" error now names CADCRAFT_MAX_DXF_TAGS.

Since #2673, converting a DWG's text happens in a separate worker process. Parsing that text into a drawing still happens in the app, which is why its limit matters.

Fixes #1948
Fixes #1465

Summary by CodeRabbit

  • Improvements
    • DXF files can now contain up to 100 million tags by default.
    • You can adjust the tag limit with the CADCRAFT_MAX_DXF_TAGS setting.
    • Error messages identify the setting to change when a DXF file exceeds the configured limit.

MrBeeboh and others added 4 commits October 22, 2026 20:20
… be refused

The tag list for a counted ASCII file is reserved once with a fallible
allocation, so where the system refuses the memory, opening fails with an error
instead of ending the app. Growing it would also take half as much again for a
moment. 100 million rather than 150 bounds a crafted 512 MB file to about 4 GB
of tags; CADCRAFT_MAX_DXF_TAGS raises it, and the error says so.
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The DXF parser now defaults to a 100-million tag limit and accepts a positive CADCRAFT_MAX_DXF_TAGS override. ASCII parsing reserves capacity based on its counted tags and returns a distinct error if reservation fails.

Changes: DXF tag parsing

Layer / File(s) Summary
Configure the DXF tag limit
crates/dxf/src/lib.rs
The default tag limit increases from 50 million to 100 million. max_tags reads a positive environment value after trimming whitespace and removing underscores. Unset, invalid, and zero values use the default. The TooLarge error text names CADCRAFT_MAX_DXF_TAGS.
Apply limits and reserve ASCII tags
crates/dxf/src/lib.rs, crates/io/src/tests.rs
parse, parse_ascii, and parse_binary use the effective limit. ASCII file parsing passes its counted group-code total to parse_ascii_counted, which reserves up to the lesser of the expected count and the limit. A reservation failure returns OutOfMemory. Tests cover override parsing and reservation outcomes, and the I/O test checks the updated error text.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • storytold/cadcraft#2457 — The higher default limit and configurable override apply to DXF files above 50 million tags; the reported 104-million-tag example requires a higher configured limit.

Suggested reviewers: vangel76, ffishman

Merge Risk: Low · up to e24c4

Some large DXF files with Unicode whitespace could be refused unnecessarily on memory-constrained systems. This is a narrow merge risk.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the DXF reader now accepts up to 100 million group codes, or a configured limit, and reports allocation failure as an error instead of exhausting memory silently. The …
Linked Issues check Passed Objectives [#1948, #1465]: Do not reject a large DWG at the old 50 million DXF group-code limit. Implemented: crates/dxf/src/lib.rs raises MAX_TAGS from 50_000_000 to 100_000_000. The doc comment cite…
Out of Scope Changes check Passed The diff touches two files: crates/dxf/src/lib.rs and crates/io/src/tests.rs. Every change ties to the linked objectives. The default limit increase and CADCRAFT_MAX_DXF_TAGS override serve #1948 and …
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Title check

Explanation

The title names the main change: the DXF reader now accepts up to 100 million group codes, or a configured limit, and reports allocation failure as an error instead of exhausting memory silently. The raw summary confirms the default limit rises from 50 million to 100 million, the CADCRAFT_MAX_DXF_TAGS override is kept, and a failed tag-list reservation returns OutOfMemory. The title is long at 103 characters, and it includes the issue reference (#1976), which the objectives show refers to the earlier PR, but the subject matches the changeset.

Full details: Linked Issues check

Explanation

Objectives [#1948, #1465]: Do not reject a large DWG at the old 50 million DXF group-code limit. Implemented: crates/dxf/src/lib.rs raises MAX_TAGS from 50_000_000 to 100_000_000. The doc comment cites the 56-million-tag drawing from #2427, and the 56,501,942-code case from #1465 now falls under the default. Objective [#1465]: a configurable limit. Implemented: max_tags() reads CADCRAFT_MAX_DXF_TAGS (trimmed, underscores removed, positive integer). Invalid, zero, or unset values fall back to the default. parse() and parse_binary() use max_tags(). Tests in limit_tests cover defaults, invalid values, and an override value. The 'too large' error text now names CADCRAFT_MAX_DXF_TAGS, and crates/io/src/tests.rs is updated to match. Reservation: parse_ascii_counted() reserves min(expected, limit) tags with try_reserve_exact and returns DxfError::OutOfMemory on refusal. The test the_tag_list_is_reserved_once_and_a_refusal_is_an_error covers this path. Non-coding or unmet items: #1465 asks for recommended memory and processing requirements. That is documentation, not a coding requirement, and the PR does not provide it. #1465 also offers an alternative loading method, but the request uses 'o' (or), and the configurable limit satisfies it. #1948 does not state its DWG tag count, so the default covers it only if the count is at most 100 million. The override covers larger files.

Full details: Out of Scope Changes check

Explanation

The diff touches two files: crates/dxf/src/lib.rs and crates/io/src/tests.rs. Every change ties to the linked objectives. The default limit increase and CADCRAFT_MAX_DXF_TAGS override serve #1948 and #1465. The OutOfMemory variant and try_reserve_exact call guard the larger tag list that the higher default allows. The error message change names the override so users can act on the limit. The io test update only follows the new error text. The new limit_tests module covers the new functions. No unrelated refactoring or feature work appears in the diff.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ast-grep (0.51.1)

ast-grep could not parse rule config: /ast-grep-rules/ast-grep-essentials/rules/ruby/security/ruby-mongo-empty-password-ruby.yml

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d180b28 and e24c455.

Files selected for processing: 2
  • crates/dxf/src/lib.rs
  • crates/io/src/tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants