summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKarol Babioch <kbabioch@suse.de>2018-03-02 14:40:58 +0100
committerEven Rouault <even.rouault@spatialys.com>2018-09-22 23:12:39 +0200
commitcc3824767bde397fedb8a1ae4786a222ba860c8d (patch)
tree3701a8a50716ec772f11ff19e52090a7e1fc74b2 /src
parent564fbfb67830e2eb234bc16b3db8fecf54261f95 (diff)
opj_mj2_extract: Check provided output prefix for length
This uses snprintf() with correct buffer length instead of sprintf(), which prevents a buffer overflow when providing a long output prefix. Furthermore the program exits with an error when the provided output prefix is too long. Fixes #1088.
Diffstat (limited to 'src')
-rw-r--r--src/bin/mj2/opj_mj2_extract.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/bin/mj2/opj_mj2_extract.c b/src/bin/mj2/opj_mj2_extract.c
index a062e17d..fa67bf85 100644
--- a/src/bin/mj2/opj_mj2_extract.c
+++ b/src/bin/mj2/opj_mj2_extract.c
@@ -140,10 +140,21 @@ int main(int argc, char *argv[])
fread(frame_codestream, sample->sample_size - 8, 1,
file); /* Assuming that jp and ftyp markers size do*/
- sprintf(outfilename, "%s_%05d.j2k", argv[2], snum);
+ {
+ int num = snprintf(outfilename, sizeof(outfilename),
+ "%s_%05d.j2k", argv[2],
+ snum);
+ if (num >= sizeof(outfilename)) {
+ fprintf(stderr, "maximum length of output prefix exceeded\n");
+ free(frame_codestream);
+ return 1;
+ }
+ }
+
outfile = fopen(outfilename, "wb");
if (!outfile) {
fprintf(stderr, "failed to open %s for writing\n", outfilename);
+ free(frame_codestream);
return 1;
}
fwrite(frame_codestream, sample->sample_size - 8, 1, outfile);