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)
|
PDFDoc_dealloc(PDFDoc* self)
|
||||||
{
|
{
|
||||||
if (self->doc != NULL) delete self->doc;
|
if (self->doc != NULL) delete self->doc;
|
||||||
|
Py_CLEAR(self->load_buffer_ref);
|
||||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,6 +46,8 @@ PDFDoc_load(PDFDoc *self, PyObject *args) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
self->doc->LoadFromBuffer(bufferview(buffer, size));
|
self->doc->LoadFromBuffer(bufferview(buffer, size));
|
||||||
|
self->load_buffer_ref = args;
|
||||||
|
Py_INCREF(args);
|
||||||
} catch(const PdfError & err) {
|
} catch(const PdfError & err) {
|
||||||
podofo_set_exception(err);
|
podofo_set_exception(err);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -26,6 +26,7 @@ typedef struct {
|
|||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
/* Type-specific fields go here. */
|
/* Type-specific fields go here. */
|
||||||
PdfMemDocument *doc;
|
PdfMemDocument *doc;
|
||||||
|
PyObject *load_buffer_ref;
|
||||||
|
|
||||||
} PDFDoc;
|
} PDFDoc;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user