summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_stream_acc_unittest.cpp
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2018-07-11 16:25:14 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-11 16:25:14 +0000
commit7c694a4632dc3b11e26d66a44e598a211913d02a (patch)
tree3258d86c9df382d7974b4f7e8dea2c14a6c4294b /core/fpdfapi/parser/cpdf_stream_acc_unittest.cpp
parente7e454da8e382513b9e271bb3e0be3bd901bfbd9 (diff)
downloadpdfium-7c694a4632dc3b11e26d66a44e598a211913d02a.tar.xz
Fix crash and memory leak.
Do not return size within CPDF_StreamAcc in case when read data failed. Also free buffers in this case. Bug: chromium:860210 Change-Id: Ifb2a061d7c8427409b68c33f213c5c55343fb946 Reviewed-on: https://pdfium-review.googlesource.com/37310 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_stream_acc_unittest.cpp')
-rw-r--r--core/fpdfapi/parser/cpdf_stream_acc_unittest.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/core/fpdfapi/parser/cpdf_stream_acc_unittest.cpp b/core/fpdfapi/parser/cpdf_stream_acc_unittest.cpp
new file mode 100644
index 0000000000..dcebf0b3a7
--- /dev/null
+++ b/core/fpdfapi/parser/cpdf_stream_acc_unittest.cpp
@@ -0,0 +1,38 @@
+// Copyright 2018 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/fpdfapi/parser/cpdf_stream_acc.h"
+
+#include "core/fpdfapi/parser/cpdf_stream.h"
+
+#include "core/fxcrt/cfx_memorystream.h"
+#include "core/fxcrt/fx_stream.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class InvalidStream : public IFX_SeekableReadStream {
+ public:
+ InvalidStream() = default;
+ ~InvalidStream() override = default;
+
+ // IFX_SeekableReadStream overrides:
+ bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override {
+ // Read failure.
+ return false;
+ }
+
+ FX_FILESIZE GetSize() override { return 1024; }
+};
+
+} // namespace
+
+TEST(CPDF_StreamAccTest, ReadRawDataFailed) {
+ CPDF_Stream stream;
+ stream.InitStreamFromFile(pdfium::MakeRetain<InvalidStream>(), nullptr);
+ auto stream_acc = pdfium::MakeRetain<CPDF_StreamAcc>(&stream);
+ stream_acc->LoadAllDataRaw();
+ EXPECT_EQ(0u, stream_acc->GetSize());
+ EXPECT_FALSE(stream_acc->GetData());
+}