Bug 194957

Summary: String overflow when using StringBuilder in JSC::createError
Product: WebKit Reporter: Dominik Inführ <dominik.infuehr>
Component: New BugsAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, cdumez, cmarcelo, commit-queue, dbates, ews-watchlist, keith_miller, mark.lam, msaboff, saam, webkit-bug-importer, xan.lopez, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Dominik Inführ 2019-02-22 12:07:35 PST
String overflow when using StringBuilder in JSC::createError
Comment 1 Dominik Inführ 2019-02-22 12:28:31 PST
Created attachment 362746 [details]
Patch
Comment 2 Dominik Inführ 2019-02-22 12:44:53 PST
Created attachment 362751 [details]
Patch
Comment 3 Dominik Inführ 2019-02-22 13:15:16 PST
Created attachment 362755 [details]
Patch
Comment 4 Mark Lam 2019-02-22 13:15:46 PST
Comment on attachment 362751 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=362751&action=review

> Source/JavaScriptCore/runtime/ExceptionHelpers.cpp:213
> +        return makeString("object is not a function.");

Use makeString("object is not a function." _s) so that we'll create the string using an ASCIILiteral.
Comment 5 Mark Lam 2019-02-22 13:17:09 PST
Comment on attachment 362751 [details]
Patch

I didn't mean to un-obsolete this patch.
Comment 6 Dominik Inführ 2019-02-22 13:27:03 PST
Created attachment 362757 [details]
Patch
Comment 7 Dominik Inführ 2019-02-22 13:29:42 PST
Created attachment 362759 [details]
Patch
Comment 8 Dominik Inführ 2019-02-25 12:02:13 PST
Thanks for catching that! I've updated the patch, it should be ready for review!
Comment 9 Mark Lam 2019-02-25 18:02:05 PST
Comment on attachment 362759 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=362759&action=review

LGTM in general but can you clarify what you meant in the ChangeLog (see my question below).

> Source/WTF/ChangeLog:15
> +        When calculating the new capacity of a StringBuilder object,
> +        use a limit of MaxLength instead of MaxLength+1.  Allocating
> +        a string of size MaxLength+1 always fails, this meant that expanding
> +        a StringBuilder only works when doubling the capacity is smaller
> +        than that. A character cannot be appended to a String of size 1.4GB,
> +        since doubling the capacity doesn't fit into MaxLength anymore.
> +        Changing the maximum capacity to MaxLength allows this operation to
> +        succeed.

Yeah, this is a bug.  All string constructs have a max capacity of MaxLength.  I don't know what I was thinking when I added that +1 back then.

I would also break up this sentence so that it doesn't run on (plus some suggested edits):
Allocating a string of size MaxLength+1 always fails.  This means that expanding a StringBuilder only works when the newly doubled capacity is less or equal to MaxLength. 

Can you clarify this part, "A character cannot be appended to a String of size 1.4GB, since doubling the capacity doesn't fit into MaxLength anymore.  Changing the maximum capacity to MaxLength allows this operation to succeed.".  I'm not sure I understand that the issue here.  Can you give a concrete example of what you meant here, perhaps with values in hex form so that it's easier to see what's happening.
Comment 10 Dominik Inführ 2019-03-07 08:57:22 PST
Created attachment 363879 [details]
Patch
Comment 11 Dominik Inführ 2019-03-07 09:01:39 PST
Thanks for the review and your suggestions!

About that sentence: I agree, it's quite confusing. I just wanted to give an example for the explanation above. I dropped it now since this example only introduced confusion and your suggestion makes the explanation more clear.
Comment 12 Mark Lam 2019-03-13 14:14:50 PDT
Comment on attachment 363879 [details]
Patch

r=me
Comment 13 WebKit Commit Bot 2019-03-13 14:42:22 PDT
Comment on attachment 363879 [details]
Patch

Clearing flags on attachment: 363879

Committed r242910: <https://trac.webkit.org/changeset/242910>
Comment 14 WebKit Commit Bot 2019-03-13 14:42:24 PDT
All reviewed patches have been landed.  Closing bug.
Comment 15 Radar WebKit Bug Importer 2019-03-13 14:45:17 PDT
<rdar://problem/48863998>