Skip to content

Commit 6ee36ad

Browse files
authored
Merge pull request #213 from tmatth/yuvjpeg_crash
yuvjpeg: fix NULL dereference on invalid format string
2 parents 4b8d1ee + 24d2c9d commit 6ee36ad

1 file changed

Lines changed: 3 additions & 15 deletions

File tree

yuvjpeg.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ void extend_edge(JSAMPLE *image, int width, int height, unsigned char *yuv,
9191

9292
int main(int argc, char *argv[]) {
9393
long quality;
94-
const char *size;
95-
char *x;
94+
int matches;
9695
int luma_width;
9796
int luma_height;
9897
int chroma_width;
@@ -131,19 +130,8 @@ int main(int argc, char *argv[]) {
131130
return 1;
132131
}
133132

134-
size = argv[2];
135-
x = strchr(size, 'x');
136-
if (!x && x != size && x != (x + strlen(x) - 1)) {
137-
fprintf(stderr, "Invalid image size input!\n");
138-
return 1;
139-
}
140-
luma_width = (int)strtol(size, NULL, 10);
141-
if (errno != 0) {
142-
fprintf(stderr, "Invalid image size input!\n");
143-
return 1;
144-
}
145-
luma_height = (int)strtol(x + 1, NULL, 10);
146-
if (errno != 0) {
133+
matches = sscanf(argv[2], "%dx%d", &luma_width, &luma_height);
134+
if (matches != 2) {
147135
fprintf(stderr, "Invalid image size input!\n");
148136
return 1;
149137
}

0 commit comments

Comments
 (0)