Closed Bug 1448786 Opened 6 years ago Closed 6 years ago

Avoid UTF8ToUnicodeBuffer in OSPreferences_win.cpp

Categories

(Core :: Internationalization, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla61
Tracking Status
firefox61 --- fixed

People

(Reporter: hsivonen, Assigned: hsivonen)

References

Details

Attachments

(1 file)

UTF8ToUnicodeBuffer is going away in bug 1402247 (mostly because after my changes no Linux callers were left and I noticed a Windows caller just now).
Are locale strings arbitrary UTF-8 or are they guaranteed to be ASCII? I.e. can we use a Latin1 to UTF-16 conversion here, which involves no length calculation issues?
Flags: needinfo?(gandalf)
(In reply to Henri Sivonen (:hsivonen) from comment #0)
> UTF8ToUnicodeBuffer is going away in bug 1402247 (mostly because after my
> changes no Linux callers were left and I noticed a Windows caller just now).

(Oh, and the new code has very different assumptions about how length calculation happens than what UTF8ToUnicodeBuffer requires.)
As used here the locale should always be ASCII, but the value comes from JS over XPIDL [0] so we cannot guarantee it wont have some UTF8 in weird cases (but that's always going to be invalid input so its ok if it doesn't match anything, just don't crash :)).

[0] https://searchfox.org/mozilla-central/source/intl/locale/mozIOSPreferences.idl#98
Flags: needinfo?(gandalf)
(In reply to Zibi Braniecki [:gandalf][:zibi] from comment #3)
> As used here the locale should always be ASCII, but the value comes from JS
> over XPIDL [0] so we cannot guarantee it wont have some UTF8 in weird cases
> (but that's always going to be invalid input so its ok if it doesn't match
> anything, just don't crash :)).

Actually locale can only contain Latin1 characters because it uses ACString. (If it uses AUTF8String or AString, it can contain arbitrary Unicode characters.)
AFAICT, we don't need a manually-declared buffer on the stack and relying on the on-stack buffer provided by nsAutoString should be fine.
Attachment #8962323 - Flags: review?(gandalf)
Comment on attachment 8962323 [details]
Bug 1448786 - Avoid UTF8ToUnicodeBuffer in OSPreferences_win.cpp.

https://reviewboard.mozilla.org/r/231198/#review237424
Attachment #8962323 - Flags: review?(gandalf) → review+
Pushed by hsivonen@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/d9f8d12c6d6e
Avoid UTF8ToUnicodeBuffer in OSPreferences_win.cpp. r=gandalf
https://hg.mozilla.org/mozilla-central/rev/d9f8d12c6d6e
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla61
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: