mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix loading of PDF from data causing memory corruption because PoDoFo now expects the data to outlive the document
This commit is contained in:
parent
20e4db008e
commit
9aa1f4add6
@ -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;
|
||||
|
@ -26,6 +26,7 @@ typedef struct {
|
||||
PyObject_HEAD
|
||||
/* Type-specific fields go here. */
|
||||
PdfMemDocument *doc;
|
||||
PyObject *load_buffer_ref;
|
||||
|
||||
} PDFDoc;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user