Also introduce a convenience function that does this.
This fixes OSS-fuzz issue 32037.
pdf_xref *pdf_new_local_xref(fz_context *ctx, pdf_document *doc);
void pdf_drop_local_xref(fz_context *ctx, pdf_xref *xref);
+void pdf_drop_local_xref_and_resources(fz_context *ctx, pdf_document *doc);
/* Debug call to dump the incremental/local xrefs to the
* debug channel. */
if (doc->local_xref)
fz_write_printf(ctx, fz_stddbg(ctx), "pop and discard local_xref for annot\n");
#endif
- pdf_purge_locals_from_store(ctx, doc);
--doc->local_xref_nesting;
assert(doc->local_xref_nesting == 0);
- pdf_purge_local_font_resources(ctx, doc);
- pdf_drop_local_xref(ctx, doc->local_xref);
- doc->local_xref = NULL;
+ pdf_drop_local_xref_and_resources(ctx, doc);
}
static void pdf_update_appearance(fz_context *ctx, pdf_annot *annot)
if (doc->local_xref_nesting != 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "Can't undo/redo within an operation");
- pdf_purge_local_font_resources(ctx, doc);
- pdf_purge_locals_from_store(ctx, doc);
- pdf_drop_local_xref(ctx, doc->local_xref);
- doc->local_xref = NULL;
+ pdf_drop_local_xref_and_resources(ctx, doc);
for (frag = entry->head; frag != NULL; frag = frag->next)
{
/* The local xref isn't in force, and we're about
* to edit the document. This invalidates it, so
* throw it away. */
- pdf_purge_local_font_resources(ctx, doc);
- pdf_purge_locals_from_store(ctx, doc);
- pdf_drop_local_xref(ctx, doc->local_xref);
- doc->local_xref = NULL;
+ pdf_drop_local_xref_and_resources(ctx, doc);
}
}
{
pdf_obj *trailer = pdf_keep_obj(ctx, pdf_trailer(ctx, doc));
+ pdf_drop_local_xref_and_resources(ctx, doc);
+
if (doc->saved_xref_sections)
pdf_drop_xref_sections_imp(ctx, doc, doc->saved_xref_sections, doc->saved_num_xref_sections);
fz_free(ctx, xref);
}
+void pdf_drop_local_xref_and_resources(fz_context *ctx, pdf_document *doc)
+{
+ pdf_purge_local_font_resources(ctx, doc);
+ pdf_purge_locals_from_store(ctx, doc);
+ pdf_drop_local_xref(ctx, doc->local_xref);
+ doc->local_xref = NULL;
+}
+
void
pdf_debug_doc_changes(fz_context *ctx, pdf_document *doc)
{