aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/gif
diff options
context:
space:
mode:
authorGravatar Leon Scroggins III <scroggo@google.com>2017-07-14 16:32:31 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-14 21:14:06 +0000
commit588fb040b3ad410cdb10c87f9a7884b6eb825e90 (patch)
tree954314604fe306c899e5d44417cc1019a0a078f5 /third_party/gif
parent0274b30feeacae0bcd12f03ae96cb4721c1393a2 (diff)
Report error on failure to create SkCodec
Update NewFromStream to report an error on failure to create an SkCodec, so that a client can distinguish between - not enough data - invalid data In Chromium, this will allow blink::ImageDecoder to call SetFailed if the stream is invalid early and we never create an SkCodec. Without this, ImageDecoder will keep trying to create an SkCodec when it receives more data. Change-Id: I4f505c56d91c982be36a828fd0f7db17b1596588 Reviewed-on: https://skia-review.googlesource.com/22642 Commit-Queue: Leon Scroggins <scroggo@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com> Reviewed-by: Chris Blume <cblume@chromium.org>
Diffstat (limited to 'third_party/gif')
-rw-r--r--third_party/gif/SkGifImageReader.cpp30
-rw-r--r--third_party/gif/SkGifImageReader.h4
2 files changed, 14 insertions, 20 deletions
diff --git a/third_party/gif/SkGifImageReader.cpp b/third_party/gif/SkGifImageReader.cpp
index e76028dac9..e3b225dda7 100644
--- a/third_party/gif/SkGifImageReader.cpp
+++ b/third_party/gif/SkGifImageReader.cpp
@@ -420,17 +420,15 @@ bool SkGifImageReader::decode(int frameIndex, bool* frameComplete)
}
// Parse incoming GIF data stream into internal data structures.
-// Return true if parsing has progressed or there is not enough data.
-// Return false if a fatal error is encountered.
-bool SkGifImageReader::parse(SkGifImageReader::SkGIFParseQuery query)
+SkCodec::Result SkGifImageReader::parse(SkGifImageReader::SkGIFParseQuery query)
{
if (m_parseCompleted) {
- return true;
+ return SkCodec::kSuccess;
}
if (SkGIFLoopCountQuery == query && m_loopCount != cLoopCountNotSeen) {
// Loop count has already been parsed.
- return true;
+ return SkCodec::kSuccess;
}
// SkGIFSizeQuery and SkGIFFrameCountQuery are negative, so this is only meaningful when >= 0.
@@ -438,13 +436,13 @@ bool SkGifImageReader::parse(SkGifImageReader::SkGIFParseQuery query)
if (lastFrameToParse >= 0 && (int) m_frames.size() > lastFrameToParse
&& m_frames[lastFrameToParse]->isComplete()) {
// We have already parsed this frame.
- return true;
+ return SkCodec::kSuccess;
}
while (true) {
if (!m_streamBuffer.buffer(m_bytesToConsume)) {
// The stream does not yet have enough data.
- return true;
+ return SkCodec::kIncompleteInput;
}
switch (m_state) {
@@ -475,7 +473,7 @@ bool SkGifImageReader::parse(SkGifImageReader::SkGIFParseQuery query)
else {
// This prevents attempting to continue reading this invalid stream.
GETN(0, SkGIFDone);
- return false;
+ return SkCodec::kInvalidInput;
}
GETN(7, SkGIFGlobalHeader);
break;
@@ -687,7 +685,7 @@ bool SkGifImageReader::parse(SkGifImageReader::SkGIFParseQuery query)
if (SkGIFLoopCountQuery == query) {
m_streamBuffer.flush();
- return true;
+ return SkCodec::kSuccess;
}
} else if (netscapeExtension == 2) {
// Wait for specified # of bytes to enter buffer.
@@ -700,7 +698,7 @@ bool SkGifImageReader::parse(SkGifImageReader::SkGIFParseQuery query)
// 0,3-7 are yet to be defined netscape extension codes
// This prevents attempting to continue reading this invalid stream.
GETN(0, SkGIFDone);
- return false;
+ return SkCodec::kInvalidInput;
}
break;
}
@@ -748,7 +746,7 @@ bool SkGifImageReader::parse(SkGifImageReader::SkGIFParseQuery query)
if (!height || !width) {
// This prevents attempting to continue reading this invalid stream.
GETN(0, SkGIFDone);
- return false;
+ return SkCodec::kInvalidInput;
}
}
@@ -778,7 +776,7 @@ bool SkGifImageReader::parse(SkGifImageReader::SkGIFParseQuery query)
// The decoder needs to stop, so we return here, before
// flushing the buffer. Next time through, we'll be in the same
// state, requiring the same amount in the buffer.
- return true;
+ return SkCodec::kSuccess;
}
@@ -830,7 +828,7 @@ bool SkGifImageReader::parse(SkGifImageReader::SkGIFParseQuery query)
GETN(1, SkGIFImageStart);
if (lastFrameToParse >= 0 && (int) m_frames.size() > lastFrameToParse) {
m_streamBuffer.flush();
- return true;
+ return SkCodec::kSuccess;
}
}
break;
@@ -838,20 +836,18 @@ bool SkGifImageReader::parse(SkGifImageReader::SkGIFParseQuery query)
case SkGIFDone: {
m_parseCompleted = true;
- return true;
+ return SkCodec::kSuccess;
}
default:
// We shouldn't ever get here.
// This prevents attempting to continue reading this invalid stream.
GETN(0, SkGIFDone);
- return false;
+ return SkCodec::kInvalidInput;
break;
} // switch
m_streamBuffer.flush();
}
-
- return true;
}
bool SkGifImageReader::hasTransparency(int transparentPixel, bool isLocalColormapDefined,
diff --git a/third_party/gif/SkGifImageReader.h b/third_party/gif/SkGifImageReader.h
index 49655c23df..0b89b04818 100644
--- a/third_party/gif/SkGifImageReader.h
+++ b/third_party/gif/SkGifImageReader.h
@@ -312,9 +312,7 @@ public:
// Parse incoming GIF data stream into internal data structures.
// Non-negative values are used to indicate to parse through that frame.
- // Return true if parsing has progressed or there is not enough data.
- // Return false if a fatal error is encountered.
- bool parse(SkGIFParseQuery);
+ SkCodec::Result parse(SkGIFParseQuery);
// Decode the frame indicated by frameIndex.
// frameComplete will be set to true if the frame is completely decoded.