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

Side by Side Diff: third_party/libwebp/dec/vp8l.c

Issue 25563003: libwebp: cherry-pick lossless signature check improvement (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/libwebp/README.chromium ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 Google Inc. All Rights Reserved. 1 // Copyright 2012 Google Inc. All Rights Reserved.
2 // 2 //
3 // Use of this source code is governed by a BSD-style license 3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the COPYING file in the root of the source 4 // that can be found in the COPYING file in the root of the source
5 // tree. An additional intellectual property rights grant can be found 5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may 6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree. 7 // be found in the AUTHORS file in the root of the source tree.
8 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
9 // 9 //
10 // main entry for the decoder 10 // main entry for the decoder
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 }; 75 };
76 76
77 static int DecodeImageStream(int xsize, int ysize, 77 static int DecodeImageStream(int xsize, int ysize,
78 int is_level0, 78 int is_level0,
79 VP8LDecoder* const dec, 79 VP8LDecoder* const dec,
80 uint32_t** const decoded_data); 80 uint32_t** const decoded_data);
81 81
82 //------------------------------------------------------------------------------ 82 //------------------------------------------------------------------------------
83 83
84 int VP8LCheckSignature(const uint8_t* const data, size_t size) { 84 int VP8LCheckSignature(const uint8_t* const data, size_t size) {
85 return (size >= 1) && (data[0] == VP8L_MAGIC_BYTE); 85 return (size >= VP8L_FRAME_HEADER_SIZE &&
86 data[0] == VP8L_MAGIC_BYTE &&
87 (data[4] >> 5) == 0); // version
86 } 88 }
87 89
88 static int ReadImageInfo(VP8LBitReader* const br, 90 static int ReadImageInfo(VP8LBitReader* const br,
89 int* const width, int* const height, 91 int* const width, int* const height,
90 int* const has_alpha) { 92 int* const has_alpha) {
91 const uint8_t signature = VP8LReadBits(br, 8); 93 if (VP8LReadBits(br, 8) != VP8L_MAGIC_BYTE) return 0;
92 if (!VP8LCheckSignature(&signature, 1)) {
93 return 0;
94 }
95 *width = VP8LReadBits(br, VP8L_IMAGE_SIZE_BITS) + 1; 94 *width = VP8LReadBits(br, VP8L_IMAGE_SIZE_BITS) + 1;
96 *height = VP8LReadBits(br, VP8L_IMAGE_SIZE_BITS) + 1; 95 *height = VP8LReadBits(br, VP8L_IMAGE_SIZE_BITS) + 1;
97 *has_alpha = VP8LReadBits(br, 1); 96 *has_alpha = VP8LReadBits(br, 1);
98 VP8LReadBits(br, VP8L_VERSION_BITS); // Read/ignore the version number. 97 if (VP8LReadBits(br, VP8L_VERSION_BITS) != 0) return 0;
99 return 1; 98 return 1;
100 } 99 }
101 100
102 int VP8LGetInfo(const uint8_t* data, size_t data_size, 101 int VP8LGetInfo(const uint8_t* data, size_t data_size,
103 int* const width, int* const height, int* const has_alpha) { 102 int* const width, int* const height, int* const has_alpha) {
104 if (data == NULL || data_size < VP8L_FRAME_HEADER_SIZE) { 103 if (data == NULL || data_size < VP8L_FRAME_HEADER_SIZE) {
105 return 0; // not enough data 104 return 0; // not enough data
105 } else if (!VP8LCheckSignature(data, data_size)) {
106 return 0; // bad signature
106 } else { 107 } else {
107 int w, h, a; 108 int w, h, a;
108 VP8LBitReader br; 109 VP8LBitReader br;
109 VP8LInitBitReader(&br, data, data_size); 110 VP8LInitBitReader(&br, data, data_size);
110 if (!ReadImageInfo(&br, &w, &h, &a)) { 111 if (!ReadImageInfo(&br, &w, &h, &a)) {
111 return 0; 112 return 0;
112 } 113 }
113 if (width != NULL) *width = w; 114 if (width != NULL) *width = w;
114 if (height != NULL) *height = h; 115 if (height != NULL) *height = h;
115 if (has_alpha != NULL) *has_alpha = a; 116 if (has_alpha != NULL) *has_alpha = a;
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 VP8LClear(dec); 1241 VP8LClear(dec);
1241 assert(dec->status_ != VP8_STATUS_OK); 1242 assert(dec->status_ != VP8_STATUS_OK);
1242 return 0; 1243 return 0;
1243 } 1244 }
1244 1245
1245 //------------------------------------------------------------------------------ 1246 //------------------------------------------------------------------------------
1246 1247
1247 #if defined(__cplusplus) || defined(c_plusplus) 1248 #if defined(__cplusplus) || defined(c_plusplus)
1248 } // extern "C" 1249 } // extern "C"
1249 #endif 1250 #endif
OLDNEW
« no previous file with comments | « third_party/libwebp/README.chromium ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698