Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 293b864bb85a063e57eadde164e0af5a8cea8de0
https://github.com/WebKit/WebKit/commit/293b864bb85a063e57eadde164e0af5a8cea8de0
Author: Mark Lam <[email protected]>
Date: 2025-11-11 (Tue, 11 Nov 2025)
Changed paths:
A JSTests/stress/PrintStream-truncation-for-extremely-long-strings.js
M Source/WTF/wtf/PrintStream.cpp
Log Message:
-----------
PrintStream should truncate extremely long strings when printing.
https://bugs.webkit.org/show_bug.cgi?id=302313
rdar://158662656
Reviewed by Yijia Huang.
Under the hood, PrintStream uses vnsprintf() to print a string. However,
vnsprintf() refuses
to print any string that is INT_MAX (or more) in length. Realistically, we
would never need
to print an INT_MAX length string anyway.
However, this appears to be tripping up fuzzers. So, let's just add a quality
of life
improvement to truncate that strings being printed if it is extremely long.
For this patch,
we'll add a check to see if the string is greater than 1000000 characters long.
If so, only
print the first 1000 followed by a footer that says something like "...[<N>
characters not
shown]" where N is the number of characters we truncated.
This truncation is only done when PrintStream is used to print a CString, for
which we can
cheaply do a length check. We could apply the same logic to a const char*
string, but that
would require a strlen() computation, which has some performance cost. At this
time, we're
opting not to do that. Since this is just a best effort quality of life
improvement, and
not a critical bug fix, this tradeoff choice is fine.
Test: JSTests/stress/PrintStream-truncation-for-extremely-long-strings.js
* JSTests/stress/PrintStream-truncation-for-extremely-long-strings.js: Added.
* Source/WTF/wtf/PrintStream.cpp:
(WTF::printInternal):
Canonical link: https://commits.webkit.org/302853@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications