Commit e1219cda authored by Michael Niedermayer's avatar Michael Niedermayer

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: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 6f9ae391
...@@ -218,10 +218,12 @@ static char *doubles2str(double *dp, int count, const char *sep) ...@@ -218,10 +218,12 @@ static char *doubles2str(double *dp, int count, const char *sep)
{ {
int i; int i;
char *ap, *ap0; char *ap, *ap0;
int component_len; uint64_t component_len;
if (!sep) sep = ", "; if (!sep) sep = ", ";
component_len = 15 + strlen(sep); component_len = 15LL + strlen(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) if (!ap)
return NULL; return NULL;
ap0 = ap; ap0 = ap;
...@@ -242,14 +244,22 @@ static char *shorts2str(int16_t *sp, int count, const char *sep) ...@@ -242,14 +244,22 @@ static char *shorts2str(int16_t *sp, int count, const char *sep)
{ {
int i; int i;
char *ap, *ap0; char *ap, *ap0;
uint64_t component_len;
if (!sep) sep = ", "; 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) if (!ap)
return NULL; return NULL;
ap0 = ap; ap0 = ap;
ap[0] = '\0'; ap[0] = '\0';
for (i = 0; i < count; i++) { 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; ap += l;
} }
ap0[strlen(ap0) - strlen(sep)] = '\0'; ap0[strlen(ap0) - strlen(sep)] = '\0';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment