-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/image/bmp: out of memory #10399
Comments
The test bmp size is 16x1073741836, bpp is 32. |
My understanding is that BMP is not compressed format. So decoding must try to allocate 16x1073741836x4 only if input size is larger than that. In this case input is few bytes, so an attempt to allocate 64GB of memory does look like a bug. |
BMP does support RLE compression. I'm not sure x/image/bmp supports RLE
though.
|
@minux x/image/bmp does not supports any compression. |
@dvyukov, use Go 1.5 milestone for bugs in released code. Subrepos are not released. The code in x/image/bmp and Go 1.5 are completely unrelated. The milestone for subrepos is Unreleased. |
BMP is not a compressed format, but the structure of the file format is first header, then payload. The image dimensions are in the header, and the decoder allocates a pixel buffer after the header is processed but before the payload is processed, because processing the payload involves writing the pixels to somewhere: the pixel buffer. Decode takes an io.Reader, not an io.ReadSeeker, so at the time it allocates the pixel buffer, it cannot know whether or not there's 'enough input' remaining. Conversely, we may be decoding an image downloaded from a socket, where we cannot know how much input is remaining. So I think this is all WAI. For decoding images in general, with compression, knowing the total file size doesn't necessarily mean that you know whether or not there's enough pixel data. LZW-style length-difference or RLE encoding means that very large uncompressed data can compress very, very well. That the various image libraries should reject an 16x1073741836 early, checking some sort of MaxMem option before allocating a buffer, is issue #5050. |
Run the following program on the following input:
https://drive.google.com/file/d/0B20Uwp8Hs1oCTzFrMndWMjNtTHM/view?usp=sharing
It crashes as:
I am on commit 65a798f031fd31a65574938bed2ec44c2bcba496
The text was updated successfully, but these errors were encountered: