Artifacts Associated With Ticket 00655c867e
Ticket change [129332b760] (rid 214767) by chrstphrchvz on 2023-05-09 21:05:40:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
clock-61.3 triggers an <tt>-fsanitize=signed-integer-overflow</tt> error: <pre> generic/tclClock.c:472:52: runtime error: signed integer overflow: 9223372036854775807 + 210866803200 cannot be represented in type 'long long' </pre> See attached patch. To avoid the overflow, I suggest dividing by <tt>SECONDS_PER_DAY</tt> first and then adding <tt>JULIAN_DAY_POSIX_EPOCH</tt> instead. The quotient also needs to be consistently rounded down, rather truncated towards 0 (GNU C and C99) or however a particular platform chooses (C89); otherwise incorrect results are produced for time values prior to the POSIX epoch. Not rounding down already produces incorrect results for time values prior to Julian day 0; the proposed clock-7.10 test currently fails with <pre>-210866803200 -210866889600 -1 -210866803201 0 -210866803200 0 0 0</pre> when integer division truncates toward 0.
- foundin initialized to: "core-8-6-branch"
- is_private initialized to: "0"
- login: "chrstphrchvz"
- priority initialized to: "5 Medium"
- private_contact initialized to: "6133eb3026f9b10aa9b7b48da92ae2834fc225b0"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "chrstphrchvz"
- subsystem initialized to: "16. Commands A-H"
- title initialized to:
ClockGetdatefieldsObjCmd(): avoid signed integer overflow and platform-dependent behavior
- type initialized to: "Patch"
Add attachment "00655c867eab.diff" [e83aa4bc3e] (rid 214769) by chrstphrchvz on 2023-05-09 21:16:27.
Ticket change [9823740c38] (rid 218205) by jan.nijtmans on 2023-09-14 21:19:34:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2460202.38858978"
- closer changed to: "jan.nijtmans"
- icomment:
Fixed [ee677ecc84710dfd|here]. Many thanks!
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [45f0f2a9ec] (rid 218522) by jan.nijtmans on 2023-09-20 13:37:47:
- closer changed to: "nobody"
- icomment:
The new testcase fails in a OPTS=static,msvcrt build in Visual Studio, passes in all other configurations. <pre> clock.test ==== clock-7.10 Julian Day, negative amount FAILED ==== Contents of test case: # Note: %J does not accept negative input; # add negative amounts to Julian day 0 instead set s0 [clock scan 0 -format %J -gmt true] set J0 [scan [clock format $s0 -format %J -gmt true] %lld] set s0m1d [clock add $s0 -1 days] set s0m24h [clock add $s0 -24 hours] set J0m24h [scan [clock format $s0m24h -format %J -gmt true] %lld] set s0m1s [clock add $s0 -1 seconds] set J0m1s [scan [clock format $s0m1s -format %J -gmt true] %lld] list $s0m1d $s0m24h $J0m24h $s0m1s $J0m1s $s0 $J0 [::tcl::mathop::== $s0m1d $s0m24h] [::tcl::mathop::== $J0m24h $J0m1s] ---- Test generated error; Return code was: 1 ---- Return code should have been one of: 0 2 ---- errorInfo: localtime failed (clock value may be too large/small to represent) while executing "return -options $opts $result" (procedure "::tcl::clock::add" line 98) invoked from within "clock add $s0 -1 days" ("uplevel" body line 6) invoked from within "uplevel 1 $script" ---- errorCode: CLOCK localtimeFailed ==== clock-7.10 FAILED cmdAH.test </pre> - login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- status changed to: "Pending"
Ticket change [2f4268f4a2] (rid 218523) by chrstphrchvz on 2023-09-20 15:12:23:
- icomment:
I have reproduced this locally and will take a look. Note that without the change to tclClock.c the test still fails for the same reason.
- login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [08ac420864] (rid 218530) by jan.nijtmans on 2023-09-20 15:54:28:
- icomment:
Strange also, that all tests in 8.7 pass. Why does this fail in 8.6?
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [3503ed3959] (rid 218531) by chrstphrchvz on 2023-09-20 16:57:37:
- icomment:
I notice that <tt>::tcl::clock::GetSystemTimeZone</tt> is returning <tt>:localtime</tt> when running tests for the <tt>OPTS=static,mscvrt</tt> configuration (rather than e.g. <tt>:America/Chicago</tt>), which causes <tt>ConvertUTCToLocal()</tt> to use <tt>ConvertUTCToLocalUsingC()</tt> instead of <tt>ConvertUTCToLocalUsingTable()</tt>. I am guessing this is not intentional. However I wonder if clock-7.10 should still work with <tt>:localtime</tt>, or be constrained to not run under <tt>:localtime</tt>. Either way, having a similar test which forces <tt>:localtime</tt> could be useful.
- login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [b0422cc405] (rid 218533) by chrstphrchvz on 2023-09-20 20:09:04:
- icomment:
However, the conditions under which <tt>localtime()</tt>/<tt>localtime_r()</tt> encounters errors (e.g. <tt>EOVERFLOW</tt>) are platform-dependent. So a test which uses these functions may not be portable.
- login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [021b0ac236] (rid 218534) by chrstphrchvz on 2023-09-20 20:50:33:
- icomment:
The exact cutoffs for <tt>localtime()</tt>/<tt>localtime_r()</tt> errors may depend on the platform epoch, but if <tt>struct tm</tt> is consistently defined, then I would think time values with years way outside of <tt>[1900+INT_MIN,1900+INT_MAX]</tt> will reliably cause an error. I will likely open other tickets about this.
- login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"
- icomment:
Add attachment "clock-7.10-add-utc.diff" [a21a4f2486] (rid 218536) by chrstphrchvz on 2023-09-20 21:59:44.
Ticket change [989d74d3c0] (rid 218537) by chrstphrchvz on 2023-09-20 22:02:46:
- comment changed to:
clock-61.3 triggers an <tt>-fsanitize=signed-integer-overflow</tt> error: <pre> generic/tclClock.c:472:52: runtime error: signed integer overflow: 9223372036854775807 + 210866803200 cannot be represented in type 'long long' </pre> See attached patch. To avoid the overflow, I suggest dividing by <tt>SECONDS_PER_DAY</tt> first and then adding <tt>JULIAN_DAY_POSIX_EPOCH</tt> instead. The quotient also needs to be consistently rounded down, rather truncated towards 0 (GNU C and C99) or however a particular platform chooses (C89); otherwise incorrect results are produced for time values prior to the POSIX epoch. Not rounding down already produces incorrect results for time values prior to Julian day 0; the proposed clock-7.10 test currently fails with <pre><span style="color:firebrick">-210866803200</span> -210866889600 -1 -210866803201 <span style="color:firebrick">0</span> -210866803200 0 <span style="color:firebrick">0</span> <span style="color:firebrick">0</span></pre> when integer division truncates toward 0.
- icomment:
I neglected how <tt>clock add … days</tt> takes <tt>-timezone</tt> into consideration. Specifying <tt>-timezone :UTC</tt> to <tt>clock add … days</tt> avoids the failure on <tt>OPTS=static,msvcrt</tt>, although whether <tt>GetSystemTimeZone</tt> is correct or unexpectedly <tt>:localtime</tt> is beyond the scope of this test. <tt>-timezone</tt> should likely also be specified in the test’s other <tt>clock add</tt> usage for consistency. See attached patch.
- login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"
- comment changed to:
Ticket change [352b13db5d] (rid 218568) by jan.nijtmans on 2023-09-21 11:15:36:
- closedate changed to: "2460208.96917304"
- closer changed to: "jan.nijtmans"
- icomment: "Thanks! Closing now."
- login: "jan.nijtmans"
- mimetype: "text/plain"
- status changed to: "Closed"