Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Audit GetFormatSpec for size_t

Closed / Duplicatece4483c2cb67f6b3ce417cbf471ead93282d809dCreated 5 years agoUpdated 5 days ago
Descriptionplain2022-03-11 21:13:34
The GetFormatSpec() routine used in the implementation of
[binary format] and [binary scan] is truncating the parsed
"count" value at INT_MAX (and also using INT_MAX as some kind
of signal of a parsing error??) even though the argument has
been expanded to size_t .  Worth examining to see what is the
best way forward.
Referenced by2
  • 370117495bTicket [2788582fff] [binary] ugly formatSpec parsing status still Open with 4 other changes ticket2026-10-17 08:44:34
  • dd5cd86e81Fix [2788582fff] and [ce4483c2cb]: [binary format] with huge counts or offsets panicked or returned a wrong result, because the first pass added the field sizes without checking for overflow. Report "max size for a Tcl value exceeded" instead. check-in2026-10-17 08:43:18
serhiy.storchakawiki2026-10-17 08:44:34

GetFormatSpec no longer truncates at INT_MAX since 9.0 ([06ceffb2f3]), but BinaryFormatCmd still adds the field sizes without checking for overflow: [binary format x4611686018427387904x4611686018427387904] returns an empty string and [binary format x99999999999999999999] panics (same as [2788582fff]). Proposed fix in branch binary-format-size-overflow: report "max size for a Tcl value exceeded" instead. Tests binary-81.*.

jan.nijtmanswiki2026-11-27 13:51:04

Dup of [2788582fff]

Log in (anonymous is fine) to add a comment.