Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1512)

Unified Diff: core/fpdfapi/parser/cpdf_parser_unittest.cpp

Issue 2430743003: in the attempt to fix 627393, changed IFX_FileRead's readBlock to return the length it reads
Patch Set: fix an undefined variable Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/fpdfapi/parser/cpdf_parser_unittest.cpp
diff --git a/core/fpdfapi/parser/cpdf_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_parser_unittest.cpp
index 7148c54f30d55649cad324ff4a382df7b0a826e4..8aeb9813164397eae21b122216d60662018b24b1 100644
--- a/core/fpdfapi/parser/cpdf_parser_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_parser_unittest.cpp
@@ -16,25 +16,30 @@
class CFX_TestBufferRead : public IFX_SeekableReadStream {
public:
CFX_TestBufferRead(const unsigned char* buffer_in, size_t buf_size)
- : buffer_(buffer_in), total_size_(buf_size) {}
+ : buffer_(buffer_in), total_size_(buf_size), current_pos_(0) {}
// IFX_Stream
void Release() override { delete this; }
// IFX_SeekableReadStream
- bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override {
- if (offset < 0 || offset + size > total_size_)
- return false;
+ bool IsEOF() override { return current_pos_ >= total_size_; }
+ size_t ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override {
+ if (offset < 0 || size > total_size_ ||
+ offset > total_size_ - pdfium::base::checked_cast<FX_FILESIZE>(size)) {
+ return 0;
+ }
memcpy(buffer, buffer_ + offset, size);
- return true;
+ current_pos_ = offset + pdfium::base::checked_cast<FX_FILESIZE>(size);
+ return size;
}
- FX_FILESIZE GetSize() override { return (FX_FILESIZE)total_size_; };
+ FX_FILESIZE GetSize() override { return total_size_; };
protected:
const unsigned char* buffer_;
- size_t total_size_;
+ FX_FILESIZE total_size_;
+ FX_FILESIZE current_pos_;
};
// A wrapper class to help test member functions of CPDF_Parser.

Powered by Google App Engine
This is Rietveld 408576698