From 25b3a21bb456c0ac4f0011e2a4c33374cf38a52f Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Thu, 13 Jul 2017 11:24:15 +0900 Subject: Fix atoi issue Change-Id: I39ebc9662b05f6d2f5c6bb268500ec52bdd02438 Signed-off-by: Minje Ahn --- src/media-thumb-internal.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'src/media-thumb-internal.c') diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c index bf3be75..f9e0991 100755 --- a/src/media-thumb-internal.c +++ b/src/media-thumb-internal.c @@ -341,6 +341,25 @@ int _media_thumb_get_exif_info(ExifData *ed, char *buf, int max_size, int *value return MS_MEDIA_ERR_NONE; } +static int __media_thumb_safe_atoi(char *buffer, int *si) +{ + char *end = NULL; + errno = 0; + thumb_retvm_if(buffer == NULL || si == NULL, MS_MEDIA_ERR_INTERNAL, "invalid parameter"); + + const long sl = strtol(buffer, &end, 10); + + thumb_retvm_if(end == buffer, MS_MEDIA_ERR_INTERNAL, "not a decimal number"); + thumb_retvm_if('\0' != *end, MS_MEDIA_ERR_INTERNAL, "extra characters at end of input: %s", end); + thumb_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MS_MEDIA_ERR_INTERNAL, "out of range of type long"); + thumb_retvm_if(sl > INT_MAX, MS_MEDIA_ERR_INTERNAL, "greater than INT_MAX"); + thumb_retvm_if(sl < INT_MIN, MS_MEDIA_ERR_INTERNAL, "less than INT_MIN"); + + *si = (int)sl; + + return MS_MEDIA_ERR_NONE; +} + static int _media_thumb_get_data_from_exif(ExifData *ed, void **thumb_data, int *thumb_size, @@ -401,8 +420,7 @@ static int _media_thumb_get_data_from_exif(ExifData *ed, /* Get the contents of the tag in human-readable form */ char width[10] = {0,}; exif_entry_get_value(entry, width, 10); - - *thumb_width = atoi(width); + __media_thumb_safe_atoi(width, thumb_width); } else { thumb_warn("EXIF_TAG_IMAGE_WIDTH does not exist"); *thumb_width = 0; @@ -414,8 +432,7 @@ static int _media_thumb_get_data_from_exif(ExifData *ed, /* Get the contents of the tag in human-readable form */ char height[10] = {0, }; exif_entry_get_value(entry, height, 10); - - *thumb_height = atoi(height); + __media_thumb_safe_atoi(height, thumb_height); } else { thumb_warn("EXIF_TAG_IMAGE_LENGTH does not exist"); *thumb_height = 0; @@ -431,8 +448,7 @@ static int _media_thumb_get_data_from_exif(ExifData *ed, if (entry) { char width[10] = {0,}; exif_entry_get_value(entry, width, 10); - - *origin_width = atoi(width); + __media_thumb_safe_atoi(width, origin_width); } else { thumb_warn("EXIF_TAG_PIXEL_X_DIMENSION does not exist"); *origin_width = 0; @@ -444,8 +460,7 @@ static int _media_thumb_get_data_from_exif(ExifData *ed, if (entry) { char height[10] = {0, }; exif_entry_get_value(entry, height, 10); - - *origin_height = atoi(height); + __media_thumb_safe_atoi(height, origin_height); } else { thumb_warn("EXIF_TAG_PIXEL_Y_DIMENSION does not exist"); *origin_height = 0; -- cgit v1.2.3