DirectStorage icon indicating copy to clipboard operation
DirectStorage copied to clipboard

Memory stomp due to libdeflate_gdeflate_compress_bound returning too small of a value and libdeflate_gdeflate_compress ignoring the output limit

Open elasota opened this issue 1 year ago • 3 comments

While running some tests, GDeflateDemo crashed due to stack corruption. Upon testing, it turns out that this was due to libdeflate_gdeflate_compress writing more data than libdeflate_gdeflate_compress_bound indicated was the upper limit.

Reproduction steps:

  • Extract "gdeflatecrash.bin" from the attached file
  • Compile GDeflateDemo in debug mode so stack corruption checks are enabled
  • Run GDeflateDemo /compress gdeflatecrash.bin .

gdeflatecrash.zip

elasota avatar Jun 03 '24 00:06 elasota

I guess this is actually a 2-part bug: libdeflate_gdeflate_compress_bound returns too small of a value, but libdeflate_gdeflate_compress is also supposed to fail safely if more output is written than is specified in the page buffer, which it sometimes does, but with this sample, it is stomping memory above the provided limit.

elasota avatar Jun 03 '24 21:06 elasota

Thanks for reporting this issue. I will take this issue as a bug so we can track it accordingly.

coopp avatar Oct 06 '25 19:10 coopp

This PR updated libdeflate. Can you check if the issue continues to repro with that?

larryche avatar Oct 29 '25 02:10 larryche