aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar scroggo <scroggo@google.com>2014-10-24 06:49:57 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-24 06:49:57 -0700
commitb752f9f83891a72a39d2027eb33e3aecdea9e9e8 (patch)
treee5201b776c85d38fb630171cab47389d634ad55f
parentcee4ddf1c407539bcc4b3d854570291e2b13e952 (diff)
Don't read random data in ICO check.
Check to ensure SkStream::read succeeds before checking the result. Review URL: https://codereview.chromium.org/656673005
-rw-r--r--src/images/SkImageDecoder_libico.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/images/SkImageDecoder_libico.cpp b/src/images/SkImageDecoder_libico.cpp
index 4d19714a11..cd8a292edc 100644
--- a/src/images/SkImageDecoder_libico.cpp
+++ b/src/images/SkImageDecoder_libico.cpp
@@ -405,16 +405,13 @@ DEFINE_DECODER_CREATOR(ICOImageDecoder);
static bool is_ico(SkStreamRewindable* stream) {
// Check to see if the first four bytes are 0,0,1,0
// FIXME: Is that required and sufficient?
- SkAutoMalloc autoMal(4);
- unsigned char* buf = (unsigned char*)autoMal.get();
- stream->read((void*)buf, 4);
- int reserved = read2Bytes(buf, 0);
- int type = read2Bytes(buf, 2);
- if (reserved != 0 || type != 1) {
- // This stream does not represent an ICO image.
+ char buf[4];
+ if (stream->read((void*)buf, 4) != 4) {
return false;
}
- return true;
+ int reserved = read2Bytes(buf, 0);
+ int type = read2Bytes(buf, 2);
+ return 0 == reserved && 1 == type;
}
static SkImageDecoder* sk_libico_dfactory(SkStreamRewindable* stream) {