Artifacts Associated With Ticket 2788582fffffffffffffffffffffffffffffffff
Ticket change [9299e69401] (rid 120790) by dgp on 2009-05-07 18:51:35:
- assignee initialized to: "dkf"
- cmimetype initialized to: "text/plain"
- comment initialized 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.
- foundin initialized to: "obsolete: 8.6b1.1"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "dgp"
- subsystem initialized to: "12. ByteArray Object"
- title initialized to: "[binary] ugly formatSpec parsing"
- type initialized to: "Bug"
Ticket change [7336f80cde] (rid 105004) by dgp on 2009-05-08 02:21:25:
- icomment:
besides the problems noted, the current GetFormatSpec() routine permits the return of negative values for "count" and those are the values that have the power to make Tcl_SetObjLength panic. It may be that when adding code to prevent T_SOL panics, fixing this may be the simplest route to success.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [1bd86b6141] (rid 123219) by dkf on 2009-05-11 16:21:59:
- icomment:
Perhaps it should use strtol() instead (we know there's no minus sign anyway).
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [87365f95bf] (rid 131657) by dgp on 2009-05-11 20:38:27:
- icomment:
I have a patch near ready; thanks.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [31202891cc] (rid 93371) by dkf on 2009-06-15 16:16:07:
- assignee changed to: "dgp"
Ticket change [370117495b] (rid 258478) by serhiy.storchaka on 2026-10-17 08:44:34:
- foundin changed to: "8.6.18, 9.0.5, 9.1.0"
- icomment:
The <nowiki>[binary scan]</nowiki> part is fixed since 8.6.7 ([56c454c814]). <nowiki>[binary format]</nowiki> still adds the field sizes without checking for overflow: <nowiki>[binary format x99999999999999999999]</nowiki> and <nowiki>[binary format @9223372036854775807]</nowiki> panic in 9.0 and 9.1, and in 8.6 <nowiki>[binary format x2147483647x2147483647]</nowiki> returns an empty string. Proposed fix in branch [/timeline?r=binary-format-size-overflow|binary-format-size-overflow], with [ce4483c2cb]: report "max size for a Tcl value exceeded" instead. Tests binary-81.*.
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
Ticket change [4e88d9de43] (rid 263415) by jan.nijtmans on 2026-11-27 15:25:58:
- 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"