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

Unified Diff: src/codec/SkRawCodec.cpp

Issue 1780643003: Limit the maximum buffer size of SkRawBufferedStream (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkRawCodec.cpp
diff --git a/src/codec/SkRawCodec.cpp b/src/codec/SkRawCodec.cpp
index 524a438d2905023d60de3183df0ac6358aa73f2e..337aa79785e37b4ca649ee6464d167a6c44b2729 100644
--- a/src/codec/SkRawCodec.cpp
+++ b/src/codec/SkRawCodec.cpp
@@ -199,6 +199,24 @@ public:
virtual SkMemoryStream* transferBuffer(size_t offset, size_t size) = 0;
};
+class SkSizeLimitedDynamicMemoryWStream : public SkDynamicMemoryWStream {
+public:
+ virtual ~SkSizeLimitedDynamicMemoryWStream() {}
+
+ bool write(const void* buffer, size_t size) override {
+ size_t newSize;
+ if (!safe_add_to_size_t(this->bytesWritten(), size, &newSize) ||
scroggo 2016/03/09 16:32:45 If we limit to 10,240,000, do we still need to che
yujieqin 2016/03/09 17:40:30 I still prefer to check here, because there is not
+ newSize > kMaxStreamSize) {
scroggo 2016/03/09 16:32:45 nit: this lines up with the line below. Would be b
yujieqin 2016/03/09 17:40:30 Done.
+ return false;
scroggo 2016/03/09 16:32:45 Should we print some kind of error message? It see
yujieqin 2016/03/09 17:40:30 added a SkCodecPrintf
+ }
+ return SkDynamicMemoryWStream::write(buffer, size);
scroggo 2016/03/09 16:32:45 typically in Skia, we use a typedef INHERITED to r
yujieqin 2016/03/09 17:40:30 Done.
+ }
+
+private:
+ const size_t kMaxStreamSize = 100 * 1024 * 1024; // 100MB
+};
+
+// Note: the maximum buffer size is 100MB (limited by SkSizeLimitedDynamicMemoryWStream).
class SkRawBufferedStream : public SkRawStream {
public:
// Will take the ownership of the stream.
@@ -301,7 +319,8 @@ private:
SkAutoTDelete<SkStream> fStream;
bool fWholeStreamRead;
- SkDynamicMemoryWStream fStreamBuffer;
+ // Use a size-limited stream to avoid holding too huge buffer.
+ SkSizeLimitedDynamicMemoryWStream fStreamBuffer;
const size_t kReadToEnd = 0;
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698