Artifacts Associated With Ticket 0e8fd6c6d5
Ticket change [58e788fd80] (rid 199480) by chrstphrchvz on 2022-03-22 02:02:17:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
…causing <tt>stringAlloc(STRING_MAXCHARS)</tt> or similar to eventually lead to a crash or noticeable memory corruption. Example: <pre> set a [string repeat a 1073741820] # crash when attempting to create string with longest possible unicode rep and no string rep set aa [string replace $a 0 0 $a ] </pre> After <tt>TCLFLEXARRAY</tt> ([29540d10c4]) was introduced, <tt>STRING_MAXCHARS</tt> was updated ([3a6a0399ad]), but the <tt>…- 1…</tt> seems to be misplaced (it currently makes no difference in the numerator of the expression): see attached patch. <tt>STRING_MAXCHARS</tt> apparently should return 1 less than what it currently does (i.e. 2147483638 rather than 2147483639, for 32-bit <tt>int</tt> and 16-bit <tt>Tcl_UniChar</tt>). To my knowledge there are no similar issues for other structures using <tt>TCLFLEXARRAY</tt>.
- foundin initialized to: "core-8-6-branch"
- is_private initialized to: "0"
- login: "chrstphrchvz"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "chrstphrchvz"
- subsystem initialized to: "10. Objects"
- title initialized to: "(unsigned)STRING_SIZE(STRING_MAXCHARS) is 0"
- type initialized to: "Patch"
Add attachment "string-maxchars-oboe.diff" [86c3335bd7] (rid 199481) by chrstphrchvz on 2022-03-22 02:02:42.
Ticket change [bf5f854885] (rid 199482) by chrstphrchvz on 2022-03-22 02:10:14:
- icomment:
Just an observation: when built using Clang 13.0.1 AddressSanitizer (<tt>-fsanitize=address</tt>) on macOS, running this example triggers an invalid write in <tt>realloc(ptr, 0)</tt>; the address is just before <tt>ptr</tt>, i.e. likely in the ASAN chunk header, so I wonder if this is an ASAN bug. <tt>realloc(ptr, 0)</tt> (where <tt>ptr != NULL</tt>) is expected to become undefined behavior in C23, however. Should Tcl try preventing this from happening in e.g. <tt>Tcl_Realloc()</tt>, <tt>ckrealloc()</tt>, etc.?
- login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [5bb96271ea] (rid 199548) by chrstphrchvz on 2022-03-22 18:41:41:
- icomment:
The ASan flag <tt>allocator_frees_and_returns_null_on_realloc_zero</tt> is enabled by default, so this Tcl issue effectively triggers a double free. The problem seems to be that ASan is not detecting/reporting double frees for at least some large allocations.
- login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [f588184979] (rid 199558) by jan.nijtmans on 2022-03-22 20:09:07:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2459661.3396736"
- closer changed to: "jan.nijtmans"
- icomment:
Good catch! Should be fixed now. Thanks for the report and the patch!
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [58c547008c] (rid 199590) by chrstphrchvz on 2022-03-24 01:01:51:
- closedate changed to: "2459662.54296211"
- closer changed to: "chrstphrchvz"
- icomment:
ASan issue reported: [https://github.com/google/sanitizers/issues/1502]
- login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"