Merge pull request #213 from tmatth/yuvjpeg_crash

yuvjpeg: fix NULL dereference on invalid format string
This commit is contained in:
Kornel
2016-07-15 17:08:15 +01:00
committed by GitHub

View File

@@ -91,8 +91,7 @@ void extend_edge(JSAMPLE *image, int width, int height, unsigned char *yuv,
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
long quality; long quality;
const char *size; int matches;
char *x;
int luma_width; int luma_width;
int luma_height; int luma_height;
int chroma_width; int chroma_width;
@@ -131,19 +130,8 @@ int main(int argc, char *argv[]) {
return 1; return 1;
} }
size = argv[2]; matches = sscanf(argv[2], "%dx%d", &luma_width, &luma_height);
x = strchr(size, 'x'); if (matches != 2) {
if (!x && x != size && x != (x + strlen(x) - 1)) {
fprintf(stderr, "Invalid image size input!\n");
return 1;
}
luma_width = (int)strtol(size, NULL, 10);
if (errno != 0) {
fprintf(stderr, "Invalid image size input!\n");
return 1;
}
luma_height = (int)strtol(x + 1, NULL, 10);
if (errno != 0) {
fprintf(stderr, "Invalid image size input!\n"); fprintf(stderr, "Invalid image size input!\n");
return 1; return 1;
} }