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

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

Issue 10690171: libwebp: fix some int <-> size_t mix for buffer sizes (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: even newer patch Created 8 years, 5 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') | third_party/libwebp/webp/decode.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 Google Inc. 1 // Copyright 2011 Google Inc.
2 // 2 //
3 // This code is licensed under the same terms as WebM: 3 // This code is licensed under the same terms as WebM:
4 // Software License Agreement: http://www.webmproject.org/license/software/ 4 // Software License Agreement: http://www.webmproject.org/license/software/
5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ 5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/
6 // ----------------------------------------------------------------------------- 6 // -----------------------------------------------------------------------------
7 // 7 //
8 // Everything about WebPDecBuffer 8 // Everything about WebPDecBuffer
9 // 9 //
10 // Author: Skal (pascal.massimino@gmail.com) 10 // Author: Skal (pascal.massimino@gmail.com)
(...skipping 12 matching lines...) Expand all
23 // Number of bytes per pixel for the different color-spaces. 23 // Number of bytes per pixel for the different color-spaces.
24 static const int kModeBpp[MODE_LAST] = { 3, 4, 3, 4, 4, 2, 2, 1, 1 }; 24 static const int kModeBpp[MODE_LAST] = { 3, 4, 3, 4, 4, 2, 2, 1, 1 };
25 25
26 static VP8StatusCode CheckDecBuffer(const WebPDecBuffer* const buffer) { 26 static VP8StatusCode CheckDecBuffer(const WebPDecBuffer* const buffer) {
27 int ok = 1; 27 int ok = 1;
28 WEBP_CSP_MODE mode = buffer->colorspace; 28 WEBP_CSP_MODE mode = buffer->colorspace;
29 const int width = buffer->width; 29 const int width = buffer->width;
30 const int height = buffer->height; 30 const int height = buffer->height;
31 if (mode >= MODE_YUV) { // YUV checks 31 if (mode >= MODE_YUV) { // YUV checks
32 const WebPYUVABuffer* const buf = &buffer->u.YUVA; 32 const WebPYUVABuffer* const buf = &buffer->u.YUVA;
33 const int size = buf->y_stride * height; 33 const uint64_t y_size = (uint64_t)buf->y_stride * height;
34 const int u_size = buf->u_stride * ((height + 1) / 2); 34 const uint64_t u_size = (uint64_t)buf->u_stride * ((height + 1) / 2);
35 const int v_size = buf->v_stride * ((height + 1) / 2); 35 const uint64_t v_size = (uint64_t)buf->v_stride * ((height + 1) / 2);
36 const int a_size = buf->a_stride * height; 36 const uint64_t a_size = (uint64_t)buf->a_stride * height;
37 ok &= (size <= buf->y_size); 37 ok &= (y_size <= buf->y_size);
38 ok &= (u_size <= buf->u_size); 38 ok &= (u_size <= buf->u_size);
39 ok &= (v_size <= buf->v_size); 39 ok &= (v_size <= buf->v_size);
40 ok &= (a_size <= buf->a_size); 40 ok &= (a_size <= buf->a_size);
41 ok &= (buf->y_stride >= width); 41 ok &= (buf->y_stride >= width);
42 ok &= (buf->u_stride >= (width + 1) / 2); 42 ok &= (buf->u_stride >= (width + 1) / 2);
43 ok &= (buf->v_stride >= (width + 1) / 2); 43 ok &= (buf->v_stride >= (width + 1) / 2);
44 if (buf->a) { 44 if (buf->a) {
45 ok &= (buf->a_stride >= width); 45 ok &= (buf->a_stride >= width);
46 } 46 }
47 } else { // RGB checks 47 } else { // RGB checks
48 const WebPRGBABuffer* const buf = &buffer->u.RGBA; 48 const WebPRGBABuffer* const buf = &buffer->u.RGBA;
49 ok &= (buf->stride * height <= buf->size); 49 const uint64_t size = (uint64_t)buf->stride * height;
50 ok &= (size <= buf->size);
50 ok &= (buf->stride >= width * kModeBpp[mode]); 51 ok &= (buf->stride >= width * kModeBpp[mode]);
51 } 52 }
52 return ok ? VP8_STATUS_OK : VP8_STATUS_INVALID_PARAM; 53 return ok ? VP8_STATUS_OK : VP8_STATUS_INVALID_PARAM;
53 } 54 }
54 55
55 static VP8StatusCode AllocateBuffer(WebPDecBuffer* const buffer) { 56 static VP8StatusCode AllocateBuffer(WebPDecBuffer* const buffer) {
56 const int w = buffer->width; 57 const int w = buffer->width;
57 const int h = buffer->height; 58 const int h = buffer->height;
58 59
59 if (w <= 0 || h <= 0) { 60 if (w <= 0 || h <= 0) {
(...skipping 28 matching lines...) Expand all
88 89
89 buffer->private_memory = output = (uint8_t*)malloc((size_t)total_size); 90 buffer->private_memory = output = (uint8_t*)malloc((size_t)total_size);
90 if (output == NULL) { 91 if (output == NULL) {
91 return VP8_STATUS_OUT_OF_MEMORY; 92 return VP8_STATUS_OUT_OF_MEMORY;
92 } 93 }
93 94
94 if (mode >= MODE_YUV) { // YUVA initialization 95 if (mode >= MODE_YUV) { // YUVA initialization
95 WebPYUVABuffer* const buf = &buffer->u.YUVA; 96 WebPYUVABuffer* const buf = &buffer->u.YUVA;
96 buf->y = output; 97 buf->y = output;
97 buf->y_stride = stride; 98 buf->y_stride = stride;
98 buf->y_size = (int)size; 99 buf->y_size = (size_t)size;
99 buf->u = output + size; 100 buf->u = output + size;
100 buf->u_stride = uv_stride; 101 buf->u_stride = uv_stride;
101 buf->u_size = (int)uv_size; 102 buf->u_size = (size_t)uv_size;
102 buf->v = output + size + uv_size; 103 buf->v = output + size + uv_size;
103 buf->v_stride = uv_stride; 104 buf->v_stride = uv_stride;
104 buf->v_size = (int)uv_size; 105 buf->v_size = (size_t)uv_size;
105 if (mode == MODE_YUVA) { 106 if (mode == MODE_YUVA) {
106 buf->a = output + size + 2 * uv_size; 107 buf->a = output + size + 2 * uv_size;
107 } 108 }
108 buf->a_size = (int)a_size; 109 buf->a_size = (size_t)a_size;
109 buf->a_stride = a_stride; 110 buf->a_stride = a_stride;
110 } else { // RGBA initialization 111 } else { // RGBA initialization
111 WebPRGBABuffer* const buf = &buffer->u.RGBA; 112 WebPRGBABuffer* const buf = &buffer->u.RGBA;
112 buf->rgba = output; 113 buf->rgba = output;
113 buf->stride = stride; 114 buf->stride = stride;
114 buf->size = (int)size; 115 buf->size = (size_t)size;
115 } 116 }
116 } 117 }
117 return CheckDecBuffer(buffer); 118 return CheckDecBuffer(buffer);
118 } 119 }
119 120
120 VP8StatusCode WebPAllocateDecBuffer(int w, int h, 121 VP8StatusCode WebPAllocateDecBuffer(int w, int h,
121 const WebPDecoderOptions* const options, 122 const WebPDecoderOptions* const options,
122 WebPDecBuffer* const out) { 123 WebPDecBuffer* const out) {
123 if (out == NULL || w <= 0 || h <= 0) { 124 if (out == NULL || w <= 0 || h <= 0) {
124 return VP8_STATUS_INVALID_PARAM; 125 return VP8_STATUS_INVALID_PARAM;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 src->private_memory = NULL; 189 src->private_memory = NULL;
189 } 190 }
190 } 191 }
191 } 192 }
192 193
193 //------------------------------------------------------------------------------ 194 //------------------------------------------------------------------------------
194 195
195 #if defined(__cplusplus) || defined(c_plusplus) 196 #if defined(__cplusplus) || defined(c_plusplus)
196 } // extern "C" 197 } // extern "C"
197 #endif 198 #endif
OLDNEW
« no previous file with comments | « third_party/libwebp/README.chromium ('k') | third_party/libwebp/webp/decode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698