diff options
author | James Zern <jzern@google.com> | 2013-04-13 10:33:41 -0700 |
---|---|---|
committer | James Zern <jzern@google.com> | 2013-06-11 15:00:43 -0700 |
commit | 7a650c6ad65cc77421aaf3d9aadfdfd583e54b8d (patch) | |
tree | aee4fffc384f36aea537cc671315c484dab607b2 | |
parent | 31bea324080b6547ccb83a484b8fd627dcf98e3a (diff) | |
download | libwebp-7a650c6ad65cc77421aaf3d9aadfdfd583e54b8d.tar.gz |
prevent signed int overflow in left shift ops
force unsigned when shifting by 24.
Change-Id: Ie229d252e2e4078107cd705b09397e686a321ffd
(cherry picked from commit f4f90880a8de432cdead8baed1e2b04e1afb6128)
-rw-r--r-- | examples/cwebp.c | 6 | ||||
-rw-r--r-- | src/enc/picture.c | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/examples/cwebp.c b/examples/cwebp.c index 300d2c4f..0aee03ea 100644 --- a/examples/cwebp.c +++ b/examples/cwebp.c @@ -109,15 +109,15 @@ typedef enum { static InputFileFormat GetImageType(FILE* in_file) { InputFileFormat format = UNSUPPORTED; - unsigned int magic; - unsigned char buf[4]; + uint32_t magic; + uint8_t buf[4]; if ((fread(&buf[0], 4, 1, in_file) != 1) || (fseek(in_file, 0, SEEK_SET) != 0)) { return format; } - magic = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; + magic = ((uint32_t)buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; if (magic == 0x89504E47U) { format = PNG_; } else if (magic >= 0xFFD8FF00U && magic <= 0xFFD8FFFFU) { diff --git a/src/enc/picture.c b/src/enc/picture.c index ce8f59ad..e9f78e1e 100644 --- a/src/enc/picture.c +++ b/src/enc/picture.c @@ -710,7 +710,7 @@ static int Import(WebPPicture* const picture, for (y = 0; y < height; ++y) { for (x = 0; x < width; ++x) { const int offset = step * x + y * rgb_stride; - const uint32_t argb = (a_ptr[offset] << 24) | + const uint32_t argb = ((uint32_t)a_ptr[offset] << 24) | (r_ptr[offset] << 16) | (g_ptr[offset] << 8) | (b_ptr[offset]); @@ -810,7 +810,7 @@ int WebPPictureYUVAToARGB(WebPPicture* picture) { const uint8_t* const src = picture->a + y * picture->a_stride; int x; for (x = 0; x < width; ++x) { - argb_dst[x] = (argb_dst[x] & 0x00ffffffu) | (src[x] << 24); + argb_dst[x] = (argb_dst[x] & 0x00ffffffu) | ((uint32_t)src[x] << 24); } } } |