Preserve error message if PDF document fails to open.
authorTor Andersson <[email protected]>
Thu, 17 Sep 2020 12:10:17 +0000 (14:10 +0200)
committerTor Andersson <[email protected]>
Thu, 17 Sep 2020 15:15:26 +0000 (17:15 +0200)
fz_drop_document clobbers the previous error message, since it uses
fz_try internally to swallow possible cleanup errors.

source/pdf/pdf-xref.c

index 978bb15afa433b7f0af21e5398ae4693b6a39557..b1a8b73642fd6c9e39024bce3927377913c8b841 100644 (file)
@@ -2376,9 +2376,12 @@ pdf_open_document_with_stream(fz_context *ctx, fz_stream *file)
        }
        fz_catch(ctx)
        {
+               /* fz_drop_document may clobber our error code/message so we have to stash them temporarily. */
+               char message[256];
                int caught = fz_caught(ctx);
+               fz_strlcpy(message, fz_caught_message(ctx), sizeof message);
                fz_drop_document(ctx, &doc->super);
-               fz_throw(ctx, caught, "Failed to open doc from stream");
+               fz_throw(ctx, caught, "%s", message);
        }
        return doc;
 }