A document user text key containing U+0000 can't be read or deleted

dup_d2_single.3dm (8.1 KB)

dup_d0_control.3dm (8.2 KB)

Version: Rhino 8 SR32 (8.32.26160.13001); rhino3dm 8.32.2 (Python)
Not tested on later service releases (SR34/SR35 are available): I don’t have administrator rights on this machine and can’t update Rhino. If this no longer reproduces on a current build, please let me know.

How these keys occur in practice:
a file arrived with two keys whose stored UTF-16 contains NUL characters, Tim U+1765 U+0CC6 \0\0\0 ect\286. That is 9 bytes overwritten inside TimeSubject\286. The chunk CRC is valid, so the damaged bytes were written as-is by whatever saved the file. Neither API can create such a key: RhinoCommon SetString("NulSec\0Tail\7") and rhino3dm both store NulSec, cut off silently at the NUL.

Repro:
attached dup_d2_single.3dm (8 KB, 1 damaged key plus 6 normal ones) and dup_d0_control.3dm (identical, undamaged). Generator, which patches rhino3dm output and recomputes the chunk CRC:

import rhino3dm, struct, zlib
f = rhino3dm.File3dm(); f.Objects.AddPoint(0, 0, 0)
for i in range(6): f.Strings["Sec\\%d" % i] = "v%d" % i
k = "TimeSubject\\286"; f.Strings[k] = "Modelling"; f.Write("dup_d2_single.3dm", 8)
b = bytearray(open("dup_d2_single.3dm", "rb").read()); i = b.find(k.encode("utf-16-le"))
j = i
while not (b[j:j+4] == b"\x00\x80\x00\x40" and j + 12 <= i < j + 12 + struct.unpack_from("<q", b, j+4)[0]): j -= 1
ln = struct.unpack_from("<q", b, j+4)[0]
b[i+7:i+16] = bytes.fromhex("17c60c000000000000")
struct.pack_into("<I", b, j+12+ln-4, zlib.crc32(bytes(b[j+12:j+12+ln-4])) & 0xffffffff)
open("dup_d2_single.3dm", "wb").write(b)

Actual:

Test Result
Launch Rhino with the file Panel area shows “‘Right Container’ Container is empty”; Panels.GetPanel returns null
Switch to the file from another doc, panel visible First-chance System.NullReferenceException at Rhino.UI.ObjectProperties.UserStringItem.get_IsFunction(), wrapped in TargetInvocationException (2 of 2). Switch took 19 s against 4 s for the control (1 run each)
Same, panel hidden No exception (1 of 1)
Control file, both ways Panel shows all 8 rows
GetKey(i) Returns the cut-off key Tim\u1765\u0CC6
GetValue(i) / GetValue(key) "" / null
Delete(key), Delete(section, entry), SetString(key, null), each with the cut-off key and the full key including NULs Count unchanged
rhino3dm Strings[key] / Strings.Delete(key) '' / no effect
_-Audit3dmFile 0 errors or warnings
Same file with the 9 bytes restored (same length, CRC recomputed) Panel loads, delete works, save and reopen clean. The NUL is the only trigger.

Seen once in 2 runs and not confirmed: after the switch Rhino was left with black viewports, no document name in the title, and the _-Open prompt still pending.

Analysis:

  • Why the panel dies: keys cross into native code as NUL-terminated strings, so the stored key can’t be addressed. LoadDocumentStrings builds each row from GetValue(key), which returns null here. UserStringItem.IsFunction then dereferences the null value, and the panel never gets built.
  • No way to remove the entry: there is no Delete(int), so nothing in Rhino, RhinoCommon or rhino3dm can remove it.

Suggested fixes:

  1. Panel: build rows from GetValue(int), guard IsFunction and the value against null, and catch errors per row so one bad entry can’t break the whole panel.
  2. API: add index-based removal (StringTable.Delete(int), and the same on File3dmStringTable), and/or marshal keys with an explicit length.
  3. Reading: detect embedded U+0000 in user-string keys on read (openNURBS) and report it in Audit3dmFile.
  4. Optional: warn instead of silently cutting the key off when SetString receives a NUL.

Related: RH-97375 (open 8.x, null exception in the document-text grid, possibly the same family).

Hi @locivir,

Is here a real-world problem to solve here? Or are you just exercising your AI bot?

Thanks,

– Dale

Hi Dale,

I’m the CAD Director of Bixlers (bixlers.com). I have been working with Rhino since version 4 and we are using my own plugin in the company. I have a background in programming.

Currently we are indexing our library and in the first batch of files (~2000) we hit 9 files with this issue. Total library size is roughly 20 times larger. This is a real-world problem that I can overcome by deleting the entries and recalculating the related CRC through a script. Our files are from both internal designers and outside contractors. I can not confidentiality confirm the source of the records in question.

Concerning your AI comment, I’m building an AI model to help with the classification of our library. The issue surfaced initially during development. I traced it myself first and then used the AI for the deep diagnosis and the report.

Hi @locivir,

Thanks for the the human reply ;-). I’ve logged a ticket.

– Dale

RH-99458 is fixed in Rhino 8 Service Release 36