diff options
author | Leon Scroggins III <scroggo@google.com> | 2017-06-01 13:42:28 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-06-05 15:09:40 +0000 |
commit | d81fed9ce2b9c8f2f227cf74c2578b90aafbe196 (patch) | |
tree | 9068d9db4b13e46c99af764ca4d2e2ae567b0df9 /src/codec/SkBmpBaseCodec.h | |
parent | 98fae7001dd3e617d02825490d3a1f1f12e6c0ad (diff) |
Replace BMP calls to new with calls to malloc
A BMP can have an arbitrarily large width. We typically read a row
into a block of memory before swizzling it to the output. Rather
than calling new to create that block of memory, which may crash
when we run out of memory, call malloc, and return null if malloc
fails.
Add a common base class for Mask and Standard BMP codecs. This class
handles allocating and freeing the buffer.
Bug: b/37623797
Change-Id: I0510b76d688d030865faa481bb2fb1351dac2c97
Reviewed-on: https://skia-review.googlesource.com/18400
Reviewed-by: Matt Sarett <msarett@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'src/codec/SkBmpBaseCodec.h')
-rw-r--r-- | src/codec/SkBmpBaseCodec.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/codec/SkBmpBaseCodec.h b/src/codec/SkBmpBaseCodec.h new file mode 100644 index 0000000000..0b9f91977e --- /dev/null +++ b/src/codec/SkBmpBaseCodec.h @@ -0,0 +1,38 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SkBmpBaseCodec_DEFINED +#define SkBmpBaseCodec_DEFINED + +#include "SkBmpCodec.h" +#include "SkTemplates.h" + +/* + * Common base class for SkBmpStandardCodec and SkBmpMaskCodec. + */ +class SkBmpBaseCodec : public SkBmpCodec { +public: + ~SkBmpBaseCodec() override; + + /* + * Whether fSrcBuffer was successfully created. + * + * If false, this Codec must not be used. + */ + bool didCreateSrcBuffer() const { return fSrcBuffer != nullptr; } + +protected: + SkBmpBaseCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream, + uint16_t bitsPerPixel, SkCodec::SkScanlineOrder rowOrder); + + uint8_t* srcBuffer() { return reinterpret_cast<uint8_t*>(fSrcBuffer.get()); } + +private: + SkAutoFree fSrcBuffer; + + typedef SkBmpCodec INHERITED; +}; +#endif // SkBmpBaseCodec_DEFINED |