Chinese/Dangi calendar `overflow:"reject"` incorrectly rejects valid dates
Categories
(Core :: JavaScript Engine, defect, P2)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox151 | --- | fixed |
People
(Reporter: zzjas98, Assigned: anba)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
Steps to reproduce:
Run JS shell js --fuzzing-safe poc.js with:
var valid = Temporal.PlainDate.from(
{ calendar: "chinese", year: 38, month: 3, day: 30 },
{ overflow: "constrain" }
);
print(valid.toString());
var result = Temporal.PlainDate.from(
{ calendar: "chinese", year: 38, month: 3, day: 30 },
{ overflow: "reject" }
);
print(result.toString());
Actual results:
0038-04-20[u-ca=chinese]
poc.js:7:33 RangeError: calendar field "day" is too large: 30
Stack:
@poc.js:7:33
Expected results:
0038-04-20[u-ca=chinese]
0038-04-20[u-ca=chinese]
Confirmed that V8 can produce the expected result.
Tested on commit firefox 7dc5ce10ed470b11b8626d85a08a6f2d419095c5.
Analysis
In CreateDateFrom, the Chinese/Dangi case passes raw day to CreateDateFromCodes. The code guesses monthCode = M{min(month, 12)}. When that month code has only 29 days in the target year, ICU4X returns OutOfRange, the overflow=reject branch throws RangeError, and if (!date) return nullptr exits before the ordinal-adjustment logic can discover the correct month code. The same issue affects the previousMonthCode call and the leapMonthCode call.
In Chinese year 38, leap month M01L is at ordinal 2, so ordinal 3 maps to M02 (not the guessed M03). M03 has 29 days, so day=30 is rejected. But M02 has 30 days -- the date is valid.
The Hebrew case already has the fix: it pre-constrains day before calling CreateDateFromCodes, then re-validates after resolving the correct month code. This logic is missing from the Chinese/Dangi case.
Please let me know if I can provide more information, thanks!
| Assignee | ||
Comment 1•1 month ago
|
||
Thanks, I'll take a look!
Updated•1 month ago
|
| Assignee | ||
Updated•27 days ago
|
| Assignee | ||
Comment 2•25 days ago
|
||
This is like D275957 (bug 2005482), but for the Chinese/Dangi calendars.
To avoid duplicating too much code, the Hebrew/Chinese/Dangi calendar cases
are now merged.
The test case is similar to "non262/Temporal/PlainDate/hebrew-from-ordinal-month.js",
except that more than one leap year is tested, because leap years don't follow any
algorithmic laws for the Chinese/Dangi calendars.
Comment 5•11 days ago
|
||
Authored by https://github.com/anba
https://github.com/mozilla/enterprise-firefox/commit/3b9b3b9e5e4e00b2468ba087ae0e55d095207868
[enterprise-main] Bug 2023293: Constrain day before calling CreateDateFromCodes with overflow=reject for Chinese/Dangi calendars. r=spidermonkey-reviewers,dminor
Description
•