diff options
| author | Leon Scroggins <scroggo@google.com> | 2017-04-20 15:06:53 +0000 |
|---|---|---|
| committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-04-20 15:07:23 +0000 |
| commit | 434b6e81a5093bdd72b232de249386af3902248f (patch) | |
| tree | 3f6fb1efd225d456d38bbefec5ffdcccccc06eed /tests/CodecExactReadTest.cpp | |
| parent | 28804f3571e8eaa6f3b9d68bb1e72d99c990978a (diff) | |
Revert "Make SkPngCodec only read as much of the stream as necessary"
This reverts commit 2c65d5161260f3d45a63dcd92229bd09c8a12d53.
Reason for revert: Causing failures in Google3 (https://test.corp.google.com/ui#cl=153703311&flags=CAMQAg==&id=OCL:153703311:BASE:153703364:1492695824938:4db2240d&t=//chrome/skia/dm_wrapper:dm_wrapper) and differences in Gold. This change was not intended to change the output.
Original change's description:
> Make SkPngCodec only read as much of the stream as necessary
>
> Previously, SkPngCodec assumed that the stream only contained one
> image, which ended at the end of the stream. It read the stream in
> arbitrarily-sized chunks, and then passed that data to libpng for
> processing.
>
> If a stream contains more than one image, this may result in reading
> beyond the end of the image, making future reads read the wrong data.
>
> Now, SkPngCodec starts by reading 8 bytes at a time. After the
> signature, 8 bytes is enough to know which chunk is next and how many
> bytes are in the chunk.
>
> When decoding the size, we stop when we reach IDAT, and when decoding
> the image, we stop when we reach IEND.
>
> This manual parsing is necessary to support APNG, which is planned in
> the future. It also allows us to remove the SK_GOOGLE3_PNG_HACK, which
> was a workaround for reading more than necessary at the beginning of
> the image.
>
> Add a test that simulates the issue, by decoding a special stream that
> reports an error if the codec attempts to read beyond the end.
>
> Temporarily disable the partial decoding tests for png. A larger change
> will be necessary to get those working again, and no clients are
> currently relying on incrementally decoding PNGs (i.e. decode part of
> an image, then decode further with more data).
>
> Bug: skia:5368
> BUG:34073812
>
> Change-Id: If832f7b20565411226fb5be3c305a4d16bf9269d
> Reviewed-on: https://skia-review.googlesource.com/13900
> Commit-Queue: Leon Scroggins <scroggo@google.com>
> Reviewed-by: Matt Sarett <msarett@google.com>
>
TBR=msarett@google.com,scroggo@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Change-Id: I2f82e9960dda7bf5c646774df84320dadb7b930e
Reviewed-on: https://skia-review.googlesource.com/13971
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'tests/CodecExactReadTest.cpp')
| -rw-r--r-- | tests/CodecExactReadTest.cpp | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/tests/CodecExactReadTest.cpp b/tests/CodecExactReadTest.cpp deleted file mode 100644 index 7e0d8eaccc..0000000000 --- a/tests/CodecExactReadTest.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "Resources.h" -#include "Test.h" - -#include "SkBitmap.h" -#include "SkCodec.h" -#include "SkData.h" -#include "SkStream.h" - -namespace { -// This class emits a skiatest failure if a client attempts to read beyond its -// end. Since it is used with complete, valid images, and contains nothing -// after the encoded image data, it will emit a failure if the client attempts -// to read beyond the logical end of the data. -class MyStream : public SkStream { -public: - static MyStream* Make(const char* path, skiatest::Reporter* r) { - SkASSERT(path); - sk_sp<SkData> data(GetResourceAsData(path)); - if (!data) { - return nullptr; - } - - return new MyStream(path, std::move(data), r); - } - - size_t read(void* buf, size_t bytes) override { - const size_t remaining = fStream.getLength() - fStream.getPosition(); - if (bytes > remaining) { - ERRORF(fReporter, "Tried to read %lu bytes (only %lu remaining) from %s", - bytes, remaining, fPath); - } - return fStream.read(buf, bytes); - } - - bool rewind() override { - return fStream.rewind(); - } - - bool isAtEnd() const override { - return fStream.isAtEnd(); - } -private: - const char* fPath; - SkMemoryStream fStream; - skiatest::Reporter* fReporter; // Unowned - - MyStream(const char* path, sk_sp<SkData> data, skiatest::Reporter* r) - : fPath(path) - , fStream(std::move(data)) - , fReporter(r) - {} -}; -} // namespace - -// Test that SkPngCodec does not attempt to read its input beyond the logical -// end of its data. Some other SkCodecs do, but some Android apps rely on not -// doing so for PNGs. -DEF_TEST(Codec_end, r) { - for (const char* path : { "plane.png", - "yellow_rose.png", - "plane_interlaced.png" }) { - std::unique_ptr<MyStream> stream(MyStream::Make(path, r)); - if (!stream) { - continue; - } - - std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release())); - if (!codec) { - ERRORF(r, "Failed to create a codec from %s\n", path); - continue; - } - - auto info = codec->getInfo().makeColorType(kN32_SkColorType); - SkBitmap bm; - bm.allocPixels(info); - - auto result = codec->getPixels(bm.info(), bm.getPixels(), bm.rowBytes()); - if (result != SkCodec::kSuccess) { - ERRORF(r, "Failed to getPixels from %s. error %i", path, result); - continue; - } - - // Rewind and do an incremental decode. - result = codec->startIncrementalDecode(bm.info(), bm.getPixels(), bm.rowBytes()); - if (result != SkCodec::kSuccess) { - ERRORF(r, "Failed to startIncrementalDecode from %s. error %i", path, result); - continue; - } - - result = codec->incrementalDecode(); - if (result != SkCodec::kSuccess) { - ERRORF(r, "Failed to incrementalDecode from %s. error %i", path, result); - } - } -} |
