Closed Bug 371611 Opened 19 years ago Closed 19 years ago

crash nsIScriptableDateFormat::FormatDate for undefined year, month, day

Categories

(Core :: Internationalization, defect)

x86
All
defect
Not set
critical

Tracking

()

RESOLVED FIXED

People

(Reporter: surkov, Assigned: sciguyryan)

References

Details

Attachments

(2 files, 9 obsolete files)

Attached file testcase
crash nsIScriptableDateFormat::FormatDate for undefined year, month, day. Example: const nsIScriptableDateFormat = Components.interfaces.nsIScriptableDateFormat var dateConv = Components.classes["@mozilla.org/intl/scriptabledateformat;1"]. getService(nsIScriptableDateFormat); dateConv.FormatDate("", nsIScriptableDateFormat.dateFormatLong, undefined, undefined, undefined);
Attached patch Patch v1 (obsolete) — Splinter Review
Patch v1 Am I right in assuming the problem here is we're passing a 0 (undefined becomes 0 after conversion) for the year, month and day which is invalid. Wouldn't the fix therefore be something like this? In the case where either the year, month or day is 0 should we return |NS_ERROR_ILLEGAL_VALUE|?
Assignee: smontagu → sciguyryan
Status: NEW → ASSIGNED
Attachment #256365 - Flags: superreview?(smontagu)
Attachment #256365 - Flags: review?(smontagu)
+ return NS_ERROR_ILLEGAL_VALUE; // invalid arg value fwiw we have NS_ERROR_INVALID_ARG which'd the comment redundant :) (and a unit test would be nice)
(In reply to comment #2) > + return NS_ERROR_ILLEGAL_VALUE; // invalid arg value > > fwiw we have NS_ERROR_INVALID_ARG which'd the comment redundant :) (and a unit > test would be nice) > Fair enough - I was following the standard per line 148 so should that be changed also?
OS: Windows XP → All
Attached patch Patch v1.1 (obsolete) — Splinter Review
Patch v1.1 * As suggested by Christian - use |NS_ERROR_INVALID_ARG| over |NS_ERROR_ILLEGAL_VALUE| as its self-explanatory (also changed the second instance of this to maintain a standard).
Attachment #256365 - Attachment is obsolete: true
Attachment #256387 - Flags: superreview?(smontagu)
Attachment #256387 - Flags: review?(smontagu)
Attachment #256365 - Flags: superreview?(smontagu)
Attachment #256365 - Flags: review?(smontagu)
add an xpcshell test for this, please.
Flags: in-testsuite?
(In reply to comment #5) > add an xpcshell test for this, please. > Could we possibly add the xpcshell test to the pre-existing LocaleSelfTest.cpp file?
(In reply to comment #6) > (In reply to comment #5) > > add an xpcshell test for this, please. > > > > Could we possibly add the xpcshell test to the pre-existing LocaleSelfTest.cpp > file? > if you really wanted to. however, getting JS coverage would be better. you know where to find me on IRC if you need help
(In reply to comment #7) > if you really wanted to. however, getting JS coverage would be better. you know > where to find me on IRC if you need help > Will do. I'll take a look at writing a test for this tomorrow when I get home from school in that case. Thanks!
Attached patch Test v1 (obsolete) — Splinter Review
Test v1
Attachment #256479 - Flags: review?(sayrer)
Comment on attachment 256479 [details] [diff] [review] Test v1 looks good to me. but have the module owners review your tests. Ideally, they should be in the patch with the code.
Attachment #256479 - Flags: review?(smontagu)
Attachment #256479 - Flags: review?(sayrer)
Attachment #256479 - Flags: review+
(In reply to comment #10) > (From update of attachment 256479 [details] [diff] [review]) > looks good to me. but have the module owners review your tests. Ideally, they > should be in the patch with the code. > Thanks for the comment. I'll remember to add them with the main patch from now on.
Comment on attachment 256387 [details] [diff] [review] Patch v1.1 r=me, but I'm not a superreviewer
Attachment #256387 - Flags: superreview?(smontagu)
Attachment #256387 - Flags: superreview?(cbiesinger)
Attachment #256387 - Flags: review?(smontagu)
Attachment #256387 - Flags: review+
Comment on attachment 256479 [details] [diff] [review] Test v1 While you're here, why not add tests for too-large values of month and day? r=me either way.
Attachment #256479 - Flags: review?(smontagu) → review+
Attached patch Test v2 (obsolete) — Splinter Review
Test v2
Attachment #256479 - Attachment is obsolete: true
Attachment #256595 - Flags: review?(smontagu)
Attachment #256595 - Flags: review?(smontagu) → review+
Attachment #256387 - Flags: superreview?(cbiesinger) → superreview+
Comment on attachment 256595 [details] [diff] [review] Test v2 + /* Testing if we throw instead of crashing when we are passed 0s. */ either change the comment to say "undefined" or the code to pass zero. I'd prefer the latter. + catch (ex if (ex.result == NS_ERROR_INVALID_ARG)) { where is that constant defined?
Attachment #256595 - Flags: superreview-
and you need to change the makefile too so that this unit test runs, don't you?
Simon, do you have any idea why |make check| doesn't work in the mozilla/intl/tests/ folder? I've got an updated patch and am unable to test it because I can't seem to get make check to run without error.
(In reply to comment #17) > Simon, do you have any idea why |make check| doesn't work in the > mozilla/intl/tests/ folder? also, |make| doesn't work in there either
Grrr. It used to work, please file a bug against me. (You mean mozilla/intl/locale/tests, right?)
(In reply to comment #19) > Grrr. It used to work, please file a bug against me. (You mean > mozilla/intl/locale/tests, right?) > Yes, that's it.
Depends on: 371990
Attached patch Complete patch (v1) (obsolete) — Splinter Review
Complete patch (v1) * Includes the changes too the makefile, the test and the patch (as well as the makefile changes specified in bug 371990).
Attachment #256387 - Attachment is obsolete: true
Attachment #256595 - Attachment is obsolete: true
Attached patch Makefile tweaked (obsolete) — Splinter Review
with this patch, the test runs as expected in |make check|. However, the test fails: *** CHECK FAILED: FormatDate didn't reject invalid month value.
Attachment #256727 - Attachment is obsolete: true
Comment on attachment 256728 [details] [diff] [review] Makefile tweaked er, that patch skips the new unit/ directory in Ryan's patch but it's otherwise right.
Attached patch Complete patch (v2) (obsolete) — Splinter Review
Complete patch (v2) * With Robert's changes (thanks for all your help).
Attachment #256728 - Attachment is obsolete: true
Attachment #256731 - Flags: superreview?(cbiesinger)
Attachment #256731 - Flags: review?(smontagu)
Comment on attachment 256731 [details] [diff] [review] Complete patch (v2) did you actually test this? the makefile still needs the includes.
Attachment #256731 - Flags: superreview?(cbiesinger) → superreview-
Comment on attachment 256731 [details] [diff] [review] Complete patch (v2) My fault for ambiguous phrasing in bug 371990 comment 5: when I said "I think the lines between foo and bar can be removed" I should have added "not including the lines quoted"
Attached patch Complete patch (v2.2) (obsolete) — Splinter Review
Complete patch (v2.2) * Fixed the makefile error but the test still fails with |*** CHECK FAILED: FormatDate didn't reject invalid month value.| I don't know why this occurs, Simon - any ideas and is it still OK to request review on this patch?
Attachment #256731 - Attachment is obsolete: true
Attachment #256731 - Flags: review?(smontagu)
(In reply to comment #27) > * Fixed the makefile error but the test still fails with |*** CHECK FAILED: > FormatDate didn't reject invalid month value.| > > I don't know why this occurs, Simon - any ideas This turns out to be a feature of mktime: "In addition to computing the calendar time, mktime normalizes the supplied tm structure. The original values of the tm_wday and tm_yday components of the structure are ignored, and the original values of the other components are not restricted to the ranges indicated in the definition of the structure." So too-large values of month and day are not expected to fail and there's no point in testing for them. Sorry for the bad suggestion.
Attached patch Complete patch (v2.3) (obsolete) — Splinter Review
(In reply to comment #28) > So too-large values of month and day are not expected to fail and there's no > point in testing for them. Sorry for the bad suggestion. > Ah OK, in that case I've removed the unneeded code from the test.
Attachment #256798 - Attachment is obsolete: true
Attachment #256807 - Flags: superreview?(cbiesinger)
Attachment #256807 - Flags: review?(smontagu)
Attachment #256807 - Flags: review?(smontagu) → review+
Comment on attachment 256807 [details] [diff] [review] Complete patch (v2.3) + const nsIScriptableDateFormat = Ci.nsIScriptableDateFormat; well ok, I wouldn't bother with this, it's not much shorter than Ci.nsIScriptableDateFormat
Attachment #256807 - Flags: superreview?(cbiesinger) → superreview+
Attached patch Patch v2.4Splinter Review
patch v2.4 * Fixed the nits and hopefully ready for checkin.
Attachment #256807 - Attachment is obsolete: true
Attachment #257052 - Flags: superreview?(cbiesinger)
Attachment #257052 - Flags: superreview?(cbiesinger) → superreview+
Whiteboard: [checkin needed]
This was checked in by Sayre so thanks!
Status: ASSIGNED → RESOLVED
Closed: 19 years ago
Flags: in-testsuite? → in-testsuite+
Resolution: --- → FIXED
Whiteboard: [checkin needed]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: