DwgWriter silently loses SummaryInfo property values ≥16,383 chars; larger values corrupt the file for ODA-based readers

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

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
66/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
csharp
Domain
backend

Research direction

Start by running the self-contained C# repro, then inspect DwgWriter.writeSummaryInfo and the DwgStreamWriterAC21.WriteTextUnicode path named in the issue. Compare behavior at the 16,382/16,383-character boundary and check the generated file with an ODA-based reader. Done means long values either round-trip intact or fail loudly without producing a corrupt file.

Written by the indexing model from the issue text.

Description

Summary

A SummaryInfo custom-property value of 16,383 characters or more is silently lost by the DWG write path, and depending on size the written file is corrupt for ODA-based readers (DWG TrueView / AutoCAD refuse it with "The drawing file requires recovery"). DwgReader reads the same file back without complaint and simply drops the property, so a write→read round-trip check cannot detect either the data loss or the corruption.

Verified on 3.6.51, 3.7.1 (latest release), and master @ 91ae384a — identical behavior on all three.

Repro (self-contained, no external files)

using ACadSharp;
using ACadSharp.Entities;
using ACadSharp.IO;
using CSMath;

foreach (int len in new[] { 16000, 16382, 16383, 16500 })
{
    var doc = new CadDocument();
    doc.Header.Version = ACadVersion.AC1032;
    doc.Entities.Add(new Line { StartPoint = new XYZ(0, 0, 0), EndPoint = new XYZ(1000, 0, 0) });
    string payload = new string('A', len);
    doc.SummaryInfo.Properties.Add("test.prop", payload);

    var ms = new MemoryStream();
    using (var w = new DwgWriter(ms, doc)) { w.Write(); }

    using var r = new DwgReader(new MemoryStream(ms.ToArray()));
    var back = r.Read();
    bool has = back.SummaryInfo.Properties.TryGetValue("test.prop", out var got);
    Console.WriteLine($"len={len,6}: {(has ? (got == payload ? "intact" : $"CORRUPT ({got.Length} chars)") : "PROPERTY LOST")}");
}

Output (identical on 3.6.51 and 3.7.1, 2026-08-31):

len= 16000: intact
len= 16382: intact
len= 16383: PROPERTY LOST
len= 16500: PROPERTY LOST

Details

  • The boundary is exactly 16,382 → 16,383 characters, independent of content/encoding (ASCII and Hebrew behave identically), which points at a 14-bit/Int16 char-count limit in the text writer (16,383 × 2 bytes = Int16.MaxValue), i.e. the DwgStreamWriterAC21.WriteTextUnicode path used by DwgWriter.writeSummaryInfo.
  • The length appears to wrap mod 32,768: a 40,000-char value reads back as 7,233 chars.
  • With larger real-world values we observed several corruption shapes in the written bytes (key lost with duplicated value fragments, wrapped length fields, large zero padding); two of three such files were rejected by DWG TrueView with the recovery dialog, while DwgReader accepted all of them and silently dropped the property.

Expected

Either the full value round-trips, or the writer throws / truncates loudly. Silent loss plus a file that other CAD tools reject is the worst combination, because the library's own reader cannot see it.

Workaround we use

Cap every SummaryInfo property value below the boundary (we use 16,000 chars) before writing.

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.