From 0fd9fa8c8a37c02aaf2df0a07ded9349d6c4dcdf Mon Sep 17 00:00:00 2001 From: Alex Dolski Date: Mon, 12 Feb 2018 15:27:25 -0600 Subject: [PATCH] In case of an error, the output file is deleted only if it's a regular file --- src/bin/jp2/opj_decompress.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index 088f3a29..ddd7a69a 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -69,6 +69,8 @@ #ifdef OPJ_HAVE_LIBLCMS2 #include +#include + #endif #ifdef OPJ_HAVE_LIBLCMS1 #include @@ -1785,7 +1787,15 @@ int main(int argc, char **argv) /* destroy the codestream index */ opj_destroy_cstr_index(&cstr_index); - if (failed) { + /* delete the destination file, if it's a regular file */ + struct stat info; + int retval = lstat(parameters.outfile, &info); + int file = 1; + if (retval >= 0) { + file = S_ISREG(info.st_mode); + } + + if (failed && file != 0) { (void)remove(parameters.outfile); /* ignore return value */ } }