summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
Diffstat (limited to 'testing')
-rw-r--r--testing/fuzzers/xfa_codec_fuzzer.h4
-rw-r--r--testing/fx_string_testhelpers.cpp20
-rw-r--r--testing/fx_string_testhelpers.h21
3 files changed, 25 insertions, 20 deletions
diff --git a/testing/fuzzers/xfa_codec_fuzzer.h b/testing/fuzzers/xfa_codec_fuzzer.h
index bfc069a31d..bc40f653af 100644
--- a/testing/fuzzers/xfa_codec_fuzzer.h
+++ b/testing/fuzzers/xfa_codec_fuzzer.h
@@ -12,6 +12,7 @@
#include "core/fxge/dib/cfx_dibitmap.h"
#include "testing/fx_string_testhelpers.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/span.h"
#ifdef PDF_ENABLE_XFA_BMP
#include "core/fxcodec/codec/ccodec_bmpmodule.h"
@@ -52,7 +53,8 @@ class XFACodecFuzzer {
std::unique_ptr<CCodec_ProgressiveDecoder> decoder =
mgr->CreateProgressiveDecoder();
- auto source = pdfium::MakeRetain<CFX_BufferSeekableReadStream>(data, size);
+ auto source = pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ pdfium::make_span(data, size));
FXCODEC_STATUS status = decoder->LoadImageInfo(source, type, nullptr, true);
if (status != FXCODEC_STATUS_FRAME_READY)
return 0;
diff --git a/testing/fx_string_testhelpers.cpp b/testing/fx_string_testhelpers.cpp
index e2ce9353fb..e3c443ac4e 100644
--- a/testing/fx_string_testhelpers.cpp
+++ b/testing/fx_string_testhelpers.cpp
@@ -24,8 +24,22 @@ CFX_InvalidSeekableReadStream::CFX_InvalidSeekableReadStream(
CFX_InvalidSeekableReadStream::~CFX_InvalidSeekableReadStream() = default;
CFX_BufferSeekableReadStream::CFX_BufferSeekableReadStream(
- const unsigned char* src,
- size_t src_size)
- : data_(src), data_size_(src_size) {}
+ pdfium::span<const uint8_t> data)
+ : data_(data) {}
CFX_BufferSeekableReadStream::~CFX_BufferSeekableReadStream() = default;
+
+bool CFX_BufferSeekableReadStream::ReadBlock(void* buffer,
+ FX_FILESIZE offset,
+ size_t size) {
+ if (offset < 0 || static_cast<size_t>(offset) >= data_.size())
+ return false;
+
+ if (static_cast<size_t>(offset) + size > data_.size())
+ size = data_.size() - static_cast<size_t>(offset);
+ if (size == 0)
+ return false;
+
+ memcpy(buffer, &data_[offset], size);
+ return true;
+}
diff --git a/testing/fx_string_testhelpers.h b/testing/fx_string_testhelpers.h
index cb59cfbc03..4cddefab0a 100644
--- a/testing/fx_string_testhelpers.h
+++ b/testing/fx_string_testhelpers.h
@@ -9,6 +9,7 @@
#include "core/fxcrt/cfx_datetime.h"
#include "core/fxcrt/fx_stream.h"
+#include "third_party/base/span.h"
// Output stream operator so GTEST macros work with CFX_DateTime objects.
std::ostream& operator<<(std::ostream& os, const CFX_DateTime& dt);
@@ -37,29 +38,17 @@ class CFX_BufferSeekableReadStream : public IFX_SeekableReadStream {
friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
// IFX_SeekableReadStream:
- bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override {
- if (offset < 0 || static_cast<size_t>(offset) >= data_size_)
- return false;
-
- if (static_cast<size_t>(offset) + size > data_size_)
- size = data_size_ - static_cast<size_t>(offset);
- if (size == 0)
- return false;
-
- memcpy(buffer, data_ + offset, size);
- return true;
- }
+ bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
FX_FILESIZE GetSize() override {
- return static_cast<FX_FILESIZE>(data_size_);
+ return static_cast<FX_FILESIZE>(data_.size());
}
private:
- CFX_BufferSeekableReadStream(const unsigned char* src, size_t src_size);
+ explicit CFX_BufferSeekableReadStream(pdfium::span<const uint8_t> data);
~CFX_BufferSeekableReadStream() override;
- const unsigned char* data_;
- size_t data_size_;
+ pdfium::span<const uint8_t> data_;
};
#endif // TESTING_FX_STRING_TESTHELPERS_H_