diff options
author | Leon Scroggins III <scroggo@google.com> | 2017-01-18 12:39:07 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-01-19 14:21:02 +0000 |
commit | b3b24538e02ead0c3f5bc528818982475890efd6 (patch) | |
tree | 5511e1a441cd09b43e2eb91b1dcd22e7919d9140 /src/codec/SkBmpRLECodec.h | |
parent | 2a83603541aacc9ea6bce819c9ffde7bc246fffd (diff) |
Use fixed size buffer for RLE bmps
An RLE bmp reports how many bytes it should contain. This number may be
incorrect, or it may be a very large number. Previously, we buffered
all bytes in a single allocation. Instead, use a fixed size buffer and
only read what fits into the buffer. We already have code to refill the
buffer if there is more data, so rely on that to keep reading.
Choose an arbitrary size for the buffer. It is larger than the maximum
possible number of bytes we need to read at once.
Add a test with a test image that reports a very large number for
the number of bytes it should contain. With the old method, we would
allocate 4 gigs of memory to decode this image, which is unnecessary
and may result in OOM.
BUG=b/33251605
Change-Id: I6d66eace626002725f62237617140cab99ce42f3
Reviewed-on: https://skia-review.googlesource.com/7028
Commit-Queue: Leon Scroggins <scroggo@google.com>
Reviewed-by: Matt Sarett <msarett@google.com>
Diffstat (limited to 'src/codec/SkBmpRLECodec.h')
-rw-r--r-- | src/codec/SkBmpRLECodec.h | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/codec/SkBmpRLECodec.h b/src/codec/SkBmpRLECodec.h index 7cb3e9b292..8ea3a86dba 100644 --- a/src/codec/SkBmpRLECodec.h +++ b/src/codec/SkBmpRLECodec.h @@ -32,13 +32,10 @@ public: * @param offset the offset of the image pixel data from the end of the * headers * @param rowOrder indicates whether rows are ordered top-down or bottom-up - * @param RLEBytes indicates the amount of data left in the stream - * after decoding the headers */ SkBmpRLECodec(int width, int height, const SkEncodedInfo& info, SkStream* stream, uint16_t bitsPerPixel, uint32_t numColors, uint32_t bytesPerColor, - uint32_t offset, SkCodec::SkScanlineOrder rowOrder, - size_t RLEBytes); + uint32_t offset, SkCodec::SkScanlineOrder rowOrder); int setSampleX(int); @@ -100,9 +97,11 @@ private: const uint32_t fNumColors; const uint32_t fBytesPerColor; const uint32_t fOffset; - std::unique_ptr<uint8_t[]> fStreamBuffer; - size_t fRLEBytes; - const size_t fOrigRLEBytes; + + static constexpr size_t kBufferSize = 4096; + uint8_t fStreamBuffer[kBufferSize]; + size_t fBytesBuffered; + uint32_t fCurrRLEByte; int fSampleX; std::unique_ptr<SkSampler> fSampler; |