When structure tree is missing, assume that is broken and continue.
authorSebastian Rasmussen <[email protected]>
Fri, 3 Nov 2023 14:00:57 +0000 (15:00 +0100)
committerSebastian Rasmussen <[email protected]>
Fri, 24 Nov 2023 15:22:37 +0000 (16:22 +0100)
Previously MuPDF would throw an exception if a PDF had a cycle in
the structure tree, but now we print a warning and continue as if
the structure tree didn't exist.

source/pdf/pdf-op-run.c

index 7fb2c5057fa6552f09c92fc6afd0dfd058940e12..d0733bb0fbd24c0079f134556baeade2ceb0d547 100644 (file)
@@ -1732,6 +1732,7 @@ push_marked_content(fz_context *ctx, pdf_run_processor *proc, const char *tagstr
        int drop_tag = 1;
        fz_structure standard;
        pdf_obj *mc_dict = NULL;
+       int fallback = 0;
 
        /* Flush any pending text so it's not in the wrong layer. */
        pdf_flush_text(ctx, proc);
@@ -1765,10 +1766,18 @@ push_marked_content(fz_context *ctx, pdf_run_processor *proc, const char *tagstr
 
                /* Structure */
                if (mc_dict)
-                       send_begin_structure(ctx, proc, mc_dict);
-               else
                {
-                       /* Maybe drop this entirely? */
+                       fz_try(ctx)
+                               send_begin_structure(ctx, proc, mc_dict);
+                       fz_catch(ctx)
+                       {
+                               fz_warn(ctx, "structure tree broken, assume tree is missing: %s", fz_caught_message(ctx));
+                               fallback = 1;
+                       }
+               }
+
+               if (!mc_dict || fallback)
+               {
                        standard = structure_type(ctx, proc, tag);
                        if (standard != FZ_STRUCTURE_INVALID)
                        {