Overview
| Artifact ID: | 4e88d9de43e1316661333b2243e01a54ac769c41a3095a6477ed4df522773d3f |
|---|---|
| Ticket: | 2788582fffffffffffffffffffffffffffffffff
[binary] ugly formatSpec parsing |
| User & Date: | jan.nijtmans on 2026-11-27 15:25:58 |
Changes
- assignee changed to: "jan.nijtmans"
- closer changed to: "nobody"
- comment changed to:
The formatSpec parser for [binary format|scan] uses strtoul() to parser the count part, but then stores in an int. This yields ugly, and platform dependent results: On 32-bit system: % binary scan \x41 a0 a 1 % set a % binary scan \x41 a1 b 1 % set b A % binary scan \x41 a2 c 0 % binary scan \x41 a[expr 0x7fffffff] c 0 % binary scan \x41 a[expr 0x80000000] c 1 % set c % binary scan \x41 a[expr 0x80000001] d 1 % set d % binary scan \x41 a[expr 0xfffffffd] e 1 % set e % binary scan \x41 a[expr 0xfffffffe] f; # BINARY_NOCOUNT 1 % set f A % binary scan \x41 a[expr 0xffffffff] g; # BINARY_ALL 1 % set g A % binary scan \x41 a[expr 0x100000000] h 1 % set h A % binary scan \x41 a[expr 0x100000001] i 1 % set i A % binary scan \x41 a[expr 0x100000002] j 1 % set j A On 64-bit system: % binary scan \x41 a0 a 1 % set a % binary scan \x41 a1 b 1 % set b A % binary scan \x41 a2 c 0 % binary scan \x41 a[expr 0x7fffffff] c 0 % binary scan \x41 a[expr 0x80000000] c 1 % set c % binary scan \x41 a[expr 0x80000001] d 1 % set d % binary scan \x41 a[expr 0xfffffffd] e 1 % set e % binary scan \x41 a[expr 0xfffffffe] f; # BINARY_NOCOUNT 1 % set f A % binary scan \x41 a[expr 0xffffffff] g; # BINARY_ALL 1 % set g A % binary scan \x41 a[expr 0x100000000] h 1 % set h % binary scan \x41 a[expr 0x100000001] i 1 % set i A % binary scan \x41 a[expr 0x100000002] j 0 This has always been ugly and nonportable. Seems even more so now that bignums are the norm in many places. Good news is it's unlikely programs get here on purpose, and those that were intentionally trying to parse such long bytearrays are about to either run out of memory or overrun Tcl's limits on value storage anyway. Reporting just to get it on the record. Also someone might want to look closer if there are cases which could lead to a crash.
- icomment: "Merged to [c603fd6775|trunk]"
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- severity changed to: "Minor"
- status changed to: "Pending"