fix(task-4): refuse non-finite/non-numeric XDATA and budget 16 KB per entity

encode_values() let strings and nan/inf through float() into 1010 point
coordinates and never finiteness-checked bare 1040 reals, so
entity_set_xdata(handle, app, [["nan", 1]]) or [float("inf")] wrote a
literal "nan"/"inf" into the DXF (and every undo snapshot) and read back
as null. Numbers now go through the same rule block_specs._scalar applies:
int/float only, bool refused, math.isfinite, error naming values[i][j].

The advertised 16 KB limit was per call per app; AutoCAD's is per object
across every application (xdroom/xdsize), so three 15 KB apps on one
entity passed headless and would fail SetXData live. check_entity_budget()
now sums the entity's existing XDATA under every other app (ACAD's DSTYLE
overrides included) plus each 1001 marker with AutoCAD's resbuf sizes,
and both engines run it before registering the APPID or writing; removal
is never refused. The result's "bytes" is that same accounting.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FKFStjEFzpGyLq5bMpWxTd
This commit is contained in:
Umut CAN
2026-09-15 14:49:43 +03:00
co-authored by Claude Opus 5
parent 41d6d3505a
commit f4c2f27bee
4 changed files with 279 additions and 32 deletions
+16 -2
View File
@@ -3106,7 +3106,13 @@ class ComBackend(AutoCADBackend):
return await self._run(_sync)
async def entity_set_xdata(self, handle, app_name, values) -> dict:
from backends.xdata_specs import encode_values, validate_app_name
from backends.xdata_specs import (
app_size,
check_entity_budget,
encode_values,
split_tags_by_app,
validate_app_name,
)
# Validate and type every value before any ActiveX call: a bad
# values[i] raises here and nothing is written.
@@ -3116,6 +3122,14 @@ class ComBackend(AutoCADBackend):
def _sync():
doc = _acad_doc()
ent = doc.HandleToObject(str(handle).strip().upper())
if tags:
# The 16 KB limit is per entity across every application, the
# same gate the headless engine runs: read what is already
# there and refuse before the APPID is registered or SetXData
# gets the chance to fail half-way with AutoCAD's own error.
codes, values_ = ent.GetXData("")
existing = split_tags_by_app(list(codes or []), list(values_ or []))
check_entity_budget(app, tags, existing)
try:
doc.RegisteredApplications.Add(app)
except Exception as exc: # already registered
@@ -3133,7 +3147,7 @@ class ComBackend(AutoCADBackend):
"handle": handle,
"app_name": app,
"value_count": len(tags),
"bytes": sum(len(str(v)) for _, v in tags),
"bytes": app_size(app, tags) if tags else 0,
"removed": not tags,
"backend": "com",
}