Fix loading of PDF from data causing memory corruption because PoDoFo now expects the data to outlive the document

This commit is contained in:
Kovid Goyal 2023-05-20 11:56:10 +05:30
parent 20e4db008e
commit 9aa1f4add6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 4 additions and 0 deletions

View File

@ -18,6 +18,7 @@ static void
PDFDoc_dealloc(PDFDoc* self)
{
if (self->doc != NULL) delete self->doc;
Py_CLEAR(self->load_buffer_ref);
Py_TYPE(self)->tp_free((PyObject*)self);
}
@ -45,6 +46,8 @@ PDFDoc_load(PDFDoc *self, PyObject *args) {
try {
self->doc->LoadFromBuffer(bufferview(buffer, size));
self->load_buffer_ref = args;
Py_INCREF(args);
} catch(const PdfError & err) {
podofo_set_exception(err);
return NULL;

View File

@ -26,6 +26,7 @@ typedef struct {
PyObject_HEAD
/* Type-specific fields go here. */
PdfMemDocument *doc;
PyObject *load_buffer_ref;
} PDFDoc;