mgeisler / textwrap

An efficient and powerful Rust library for word wrapping text.
MIT License
446 stars 44 forks source link

Avoid OOM in refill fuzz test #497

Closed mgeisler closed 1 year ago

mgeisler commented 1 year ago

If two things happen at the same time:

  1. the input string has a huge prefix which is taken to be the indentation (such as “- - - - -”), and
  2. the wrapping with is set to something small (such as 0),

then we can end up allocating an enormous amount of data in the output. The problem is that we add the indentation on every line of the output, and we end up with a huge number of lines when the line width is small.

This was reported in OSS-Fuzz, please see https://oss-fuzz.com/testcase-detail/4890847154143232.