Skip to content

fix(sections): refuse an encrypted section in the legacy reader with a typed error - #315

Merged
DrunkOnJava merged 1 commit into
mainfrom
fix/r2004-encrypted-section
Oct 26, 2026
Merged

DrunkOnJava merged 1 commit into
mainfrom
fix/r2004-encrypted-section

Conversation

@DrunkOnJava

Copy link
Copy Markdown
Owner

Summary

An encrypted R2004-family section (§4.5 flag 1) is refused with a typed error by the legacy reader as well as the streaming walker; R2007's encrypted refusal uses the same variant. Refs #205; Griffin's decision relayed by the integrator.

Spec reference

ODA v5.4.1 §4.5 (encryption flag: 0 none, 1 encrypted, 2 properties only). New Error::SectionEncrypted { name }, the legacy counterpart of streaming::StreamError::SectionEncrypted. section_map::read_section_payload returns it for a flag of 1; a flag of 2 (AcDb:FileDepList, AcDb:AppInfo in real files) is still read. R2007's refusal, Error::Unsupported until now, returns the same variant (its unit test is adapted). CHANGELOG.md notes both.

Test plan

  • cargo fmt --all -- --check, cargo clippy --all-targets --all-features -- -D warnings (the build used for the next item).
  • Real files, E2E: tools/streaming/verify_sections.py repackages the sections of the canonical R2004 fixture and one real drawing per release band (line_2004, line_2010, line_2013) byte for byte in a file it builds, with AcDb:AcDbObjects flagged encrypted (a real drawing's section map has no literal byte for the flag, so it cannot be forged in place) and a control without the flag: the streaming walker and the legacy reader (--legacy, read_section_payload) read the control equal to the drawing and both refuse the flagged copy with SectionEncrypted; the built file's encrypted section is refused by the legacy reader too. All earlier cases pass unchanged.
  • No pinned drawing has the flag set to 1, so the corpus counts do not move (the Corpus job's ratchet is the check). One existing test is adapted: r2007::tests::encrypted_section_is_refused_rather_than_mis_decoded now expects Error::SectionEncrypted instead of Error::Unsupported, because that is the behaviour this PR specifies.

Source-provenance declaration

By submitting this PR I certify that my contribution does not incorporate executable code from any source whose license is incompatible with Apache-2.0. Specifically:

  • No Autodesk DWG SDK source (RealDWG, ObjectARX, ObjectDBX) or NDA-protected Autodesk documentation was consulted or imported.
  • No Open Design Alliance Teigha / Drawings SDK source was consulted or imported. The ODA's public Open Design Specification for .dwg files PDF is explicitly allowed (see CLEANROOM.md).
  • No GPL-licensed DWG implementation source (LibreDWG, etc.) was consulted or imported. This matters because dwg-rs is Apache-2.0 and must remain compatible.

My contribution is based on:

  • The ODA's freely-redistributable Open Design Specification for .dwg files (v5.4.1);
  • Measurement of the pinned public corpus (no algorithm-description comments of other projects were read for this change).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T15:19:18.869920Z bb20eed New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@DrunkOnJava
DrunkOnJava force-pushed the fix/r2004-encrypted-section branch from d5ca4f1 to a9a74a8 Compare October 26, 2026 14:51
@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 26, 2026 14:52
@DrunkOnJava
DrunkOnJava force-pushed the fix/r2004-encrypted-section branch from a9a74a8 to 1b93f37 Compare October 26, 2026 15:02
…a typed error

The R2004-family section map's encryption flag (§4.5: 0 none, 1
encrypted, 2 properties only) was ignored by the legacy reader, so a
password-protected section's ciphertext was decompressed and returned as
if it were the section; the streaming walker already refused it.
section_map::read_section_payload, and so DwgFile::read_section and the
readers built on it, now returns the new Error::SectionEncrypted { name }
for a flag of 1, the same refusal as StreamError::SectionEncrypted; a flag
of 2 marks only the properties (AcDb:FileDepList, AcDb:AppInfo in real
files) and is still read. The R2007 refusal, which was Error::Unsupported,
returns the same variant, and its unit test is adapted to it.

No pinned drawing has the flag set to 1, so the corpus counts do not move.
verify_sections.py repackages the sections of the canonical R2004 fixture
and one real drawing per release band, byte for byte, in a file it builds,
with AcDb:AcDbObjects flagged encrypted (a real drawing's section map has no
literal byte for the flag, so it cannot be forged in place) and a control
without the flag: both readers read the control equal to the drawing and
refuse the flagged copy; the built file's encrypted section is refused by
the legacy reader too.

Refs #205
@DrunkOnJava
DrunkOnJava force-pushed the fix/r2004-encrypted-section branch from 1b93f37 to bb20eed Compare October 26, 2026 15:18
@DrunkOnJava
DrunkOnJava merged commit 30d45d2 into main Oct 26, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the fix/r2004-encrypted-section branch October 26, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant