Bug 302313

Summary: PrintStream should truncate extremely long strings when printing.
Product: WebKit Reporter: Mark Lam <mark.lam>
Component: Web Template FrameworkAssignee: Mark Lam <mark.lam>
Status: RESOLVED FIXED    
Severity: Normal CC: webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

Mark Lam
Reported 2025-11-10 22:07:43 PST
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 to not do that. Since this is just a best effort quality of life improvement, and not a critical bug fix, this tradeoff choice is fine. rdar://158662656
Attachments
Mark Lam
Comment 1 2025-11-10 22:16:45 PST
EWS
Comment 2 2025-11-11 10:03:59 PST
Committed 302853@main (293b864bb85a): <https://commits.webkit.org/302853@main> Reviewed commits have been landed. Closing PR #53726 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.