Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2022-01-14
22:49 • Closed ticket [816913a65e]: GrowStringBuffer(): signed integer overflow plus... artifact: 4c61324c39 user: jan.nijtmans
09:54
Fix [816913a65e]: GrowStringBuffer(): signed integer overflow. And a few similar situations in other... check-in: 4b4cd18a44 user: jan.nijtmans tags: core-8-6-branch
2022-01-13
17:32 • Pending ticket [816913a65e]: GrowStringBuffer(): signed integer overflow plu... artifact: 18e29634a5 user: jan.nijtmans
12:22
Fix [816913a65e]: GrowStringBuffer(): signed integer overflow. And a few similar situations in other... closed check-in: a03e9793d4 user: jan.nijtmans tags: bug-816913a65e
2021-12-24
19:11 • New ticket [816913a65e] GrowStringBuffer(): signed integer overflow. artifact: 202b980e5b user: chrstphrchvz

GrowStringBuffer(): signed integer overflow

Closed / Fixed816913a65eabbd69b07be7221b68b10064103a0eCreated 5 years agoUpdated 5 years ago
Descriptionwiki2021-12-24 19:11:02
In GrowStringBuffer() (generic/tclStringObj.c), it is possible for int attempt to be assigned INT_MAX, such as when the function is called with int needed = INT_MAX. When this happens, int attempt will also be assigned INT_MAX, and attempt + 1 will overflow (although I do not observe this causing unexpected behavior). UBSan (-fsanitize=signed-integer-overflow) error example:
% set dz [open /dev/zero [list RDONLY]]
% set nulls [read $dz [expr {(1 << 30) - 1}]]
tcl/generic/tclStringObj.c:167:20: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'

If it is indeed okay to allocate (unsigned int)INT_MAX + 1U, then some possible ways to avoid overflow include declaring attempt as unsigned int, or changing instances of attempt + 1 to promote attempt to unsigned int (such as by using attempt + 1U).

Referenced by2
  • 4b4cd18a44Fix [816913a65e]: GrowStringBuffer(): signed integer overflow. And a few similar situations in other places check-in2022-01-14 09:54:48
  • a03e9793d4Fix [816913a65e]: GrowStringBuffer(): signed integer overflow. And a few similar situations in other place check-in2022-01-13 12:22:51
jan.nijtmanswiki2022-01-13 17:32:06

Possible fix committed [here]

jan.nijtmans Closed ticket [816913a65e]. [History diff]2022-01-14 22:49:30
Log in (anonymous is fine) to add a comment.