DwgWriter: extended data over 32 767 bytes per application overflows its size; the object is lost on read

Open
#1,282 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
backend, databases

Research direction

Start by reading DwgObjectWriter.writeExtendedDataEntry around the reported WriteBitShort call, then trace how DwgReader reads extended data sizes. Reproduce with the provided LINE and 32,768-byte extended data, and compare with the 32,764-byte case. Done when writing handles values over the format limit without silently producing a file where the LINE disappears on read.

Written by the indexing model from the issue text.

Description

Describe the bug
DwgWriter writes the extended data of one application with a 16-bit size, without checking it. An entity whose extended data for one application is 32 768 bytes or longer is written without an error, but the size overflows. Read back with DwgReader, the object fails and is missing from the document. The log shows "Unknown code for extended data" warnings, then "Could not read LINE with handle: 73" with ArgumentException: An item with the same key has already been added. Key: 0.

DwgObjectWriter.writeExtendedDataEntry (master, v3.8.10), line 1163:

this._writer.WriteBitShort((short)mstream.Length);

To Reproduce

  1. A LINE with one AppId whose records are 8 192 × new ExtendedDataControlString(false) followed by 8 192 × new ExtendedDataControlString(true) (2 bytes each, 32 768 bytes).
  2. DwgWriter.Write(path, doc) (AC1018; AC1015 and AC1032 behave the same).
  3. new DwgReader(path).Read(): the model space is empty.

With 8 191 + 8 191 records (32 764 bytes) the LINE reads back intact.

Expected behavior
Extended data over the format's limit is refused (or left out with a notification) when writing, rather than overflowing the size and losing the whole object on read.

Version
ACadSharp 3.8.0 (NuGet); same code on master.

Dominant language
C#
Stars
873
Forks
223
Avg merge
1d 15h
Merged PRs (30d)
28

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DomCR/ACadSharp

All issues in DomCR/ACadSharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.