diff options
author | yzrh <yzrh@noema.org> | 2023-01-04 13:51:13 +0000 |
---|---|---|
committer | yzrh <yzrh@noema.org> | 2023-01-04 13:51:13 +0000 |
commit | 8276423eb8395eae3e3002442307272eff1c9e8f (patch) | |
tree | 9aff1e7d1617e4af59beb549952dbc7e22f2b65d /src/pdf_parser.c | |
parent | 7ac0971a1711233bc0eaa5e8191590612959867b (diff) | |
download | melon-8276423eb8395eae3e3002442307272eff1c9e8f.tar.gz melon-8276423eb8395eae3e3002442307272eff1c9e8f.tar.zst |
Prioritise incomplete object during deduplication.
Signed-off-by: yzrh <yzrh@noema.org>
Diffstat (limited to 'src/pdf_parser.c')
-rw-r--r-- | src/pdf_parser.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/pdf_parser.c b/src/pdf_parser.c index 781bafa..ed7bfba 100644 --- a/src/pdf_parser.c +++ b/src/pdf_parser.c @@ -183,7 +183,7 @@ pdf_load(pdf_object_t **pdf, FILE **fp, int size_buf) ptr->size - (tail - buf) - 3, ">>", 2)) != NULL && memmem(tail + 3, - ptr->size - (tail - buf) - 3, + (tmp - tail) - 3, "stream\r\n", 8) == NULL) tail = tmp; @@ -226,8 +226,27 @@ pdf_load(pdf_object_t **pdf, FILE **fp, int size_buf) free(buf); } else { - ptr->object_size = ptr->size; - ptr->object = buf; + /* Handle incomplete object */ + head = buf; + while ((tmp = _memmem_whitespace(head, + ptr->size - (head - buf), + " 0 obj", 6)) != NULL) + head = tmp + 7; + + if (head - buf > 0) { + ptr->object_size = ptr->size - (head - buf); + ptr->object = malloc(ptr->object_size); + + if (ptr->object == NULL) + return 1; + + memcpy(ptr->object, head, ptr->object_size); + + free(buf); + } else { + ptr->object_size = ptr->size; + ptr->object = buf; + } } ptr = ptr->next; |