diff options
author | Michael Niedermayer <[email protected]> | 2013-02-12 23:40:24 +0100 |
---|---|---|
committer | Michael Niedermayer <[email protected]> | 2013-03-03 02:45:08 +0100 |
commit | d17b9469c940f056d87fefc79d80fac47c69c1d8 (patch) | |
tree | 0f2739683f8e14c72d7df57c2c29519faae2aebc | |
parent | 534c0df6e0ed9f26012d77e990d4da9b73d45e48 (diff) |
tiff: Check buffer allocation and pointer increment more carefully in shorts2str() and double2str()
Fixes out of array accesses
Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <[email protected]>
(cherry picked from commit e1219cdaf9fb4bc8cea410e1caf802373c1bfe51)
Conflicts:
libavcodec/tiff.c
-rw-r--r-- | libavcodec/tiff.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index 5be154fbb2..0d2aee70fd 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -207,9 +207,11 @@ static char *doubles2str(double *dp, int count, const char *sep) { int i; char *ap, *ap0; - int component_len = 15 + strlen(sep); + uint64_t component_len = 15LL + strlen(sep); if (!sep) sep = ", "; - ap = av_malloc(component_len * count); + if (count >= (INT_MAX - 1)/component_len) + return NULL; + ap = av_malloc(component_len * count + 1); if (!ap) return NULL; ap0 = ap; @@ -228,14 +230,22 @@ static char *shorts2str(int16_t *sp, int count, const char *sep) { int i; char *ap, *ap0; + uint64_t component_len; if (!sep) sep = ", "; - ap = av_malloc((5 + strlen(sep)) * count); + component_len = 7LL + strlen(sep); + if (count >= (INT_MAX - 1)/component_len) + return NULL; + ap = av_malloc(component_len * count + 1); if (!ap) return NULL; ap0 = ap; ap[0] = '\0'; for (i = 0; i < count; i++) { - int l = snprintf(ap, 5 + strlen(sep), "%d%s", sp[i], sep); + unsigned l = snprintf(ap, component_len, "%d%s", sp[i], sep); + if (l >= component_len) { + av_free(ap0); + return NULL; + } ap += l; } ap0[strlen(ap0) - strlen(sep)] = '\0'; |