Bug 302313
| Summary: | PrintStream should truncate extremely long strings when printing. | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Mark Lam <mark.lam> |
| Component: | Web Template Framework | Assignee: | 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
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 | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Mark Lam
Pull request: https://github.com/WebKit/WebKit/pull/53726
EWS
Committed 302853@main (293b864bb85a): <https://commits.webkit.org/302853@main>
Reviewed commits have been landed. Closing PR #53726 and removing active labels.