Fix up copying objects from unencrypted to AES-encrypted documents (still looks

like there are some issues with strings in dicts)
This commit is contained in:
Michael R Sweet 2021-10-25 21:22:59 -04:00
parent 038046e6d5
commit 790cd440ea
No known key found for this signature in database
GPG Key ID: 999559A027815955
4 changed files with 40 additions and 1 deletions

View File

@ -21,6 +21,39 @@
static int compare_pairs(_pdfio_pair_t *a, _pdfio_pair_t *b); static int compare_pairs(_pdfio_pair_t *a, _pdfio_pair_t *b);
//
// '_pdfioDictClear()' - Remove a key/value pair from a dictionary.
//
void
_pdfioDictClear(pdfio_dict_t *dict, // I - Dictionary
const char *key) // I - Key
{
size_t idx; // Index into pairs
_pdfio_pair_t *pair, // Current pair
pkey; // Search key
PDFIO_DEBUG("_pdfioDictClear(dict=%p, key=\"%s\")\n", dict, key);
// See if the key is already set...
if (dict->num_pairs > 0)
{
pkey.key = key;
if ((pair = (_pdfio_pair_t *)bsearch(&pkey, dict->pairs, dict->num_pairs, sizeof(_pdfio_pair_t), (int (*)(const void *, const void *))compare_pairs)) != NULL)
{
// Yes, remove it...
idx = (size_t)(pair - dict->pairs);
dict->num_pairs --;
if (idx < dict->num_pairs)
memmove(pair, pair + 1, (dict->num_pairs - idx) * sizeof(_pdfio_pair_t));
}
}
}
// //
// 'pdfioDictCopy()' - Copy a dictionary to a PDF file. // 'pdfioDictCopy()' - Copy a dictionary to a PDF file.
// //

View File

@ -96,6 +96,9 @@ pdfioObjCopy(pdfio_file_t *pdf, // I - PDF file
if (!_pdfioValueCopy(pdf, &dstobj->value, srcobj->pdf, &srcobj->value)) if (!_pdfioValueCopy(pdf, &dstobj->value, srcobj->pdf, &srcobj->value))
return (NULL); return (NULL);
if (dstobj->value.type == PDFIO_VALTYPE_DICT)
_pdfioDictClear(dstobj->value.value.dict, "Length");
if (srcobj->stream_offset) if (srcobj->stream_offset)
{ {
// Copy stream data... // Copy stream data...

View File

@ -361,6 +361,7 @@ extern void _pdfioCryptoSHA256Init(_pdfio_sha256_t *ctx) _PDFIO_INTERNAL;
extern void _pdfioCryptoSHA256Finish(_pdfio_sha256_t *ctx, uint8_t *Message_Digest) _PDFIO_INTERNAL; extern void _pdfioCryptoSHA256Finish(_pdfio_sha256_t *ctx, uint8_t *Message_Digest) _PDFIO_INTERNAL;
extern bool _pdfioCryptoUnlock(pdfio_file_t *pdf, pdfio_password_cb_t password_cb, void *password_data) _PDFIO_INTERNAL; extern bool _pdfioCryptoUnlock(pdfio_file_t *pdf, pdfio_password_cb_t password_cb, void *password_data) _PDFIO_INTERNAL;
extern void _pdfioDictClear(pdfio_dict_t *dict, const char *key) _PDFIO_INTERNAL;
extern void _pdfioDictDebug(pdfio_dict_t *dict, FILE *fp) _PDFIO_INTERNAL; extern void _pdfioDictDebug(pdfio_dict_t *dict, FILE *fp) _PDFIO_INTERNAL;
extern void _pdfioDictDelete(pdfio_dict_t *dict) _PDFIO_INTERNAL; extern void _pdfioDictDelete(pdfio_dict_t *dict) _PDFIO_INTERNAL;
extern _pdfio_value_t *_pdfioDictGetValue(pdfio_dict_t *dict, const char *key) _PDFIO_INTERNAL; extern _pdfio_value_t *_pdfioDictGetValue(pdfio_dict_t *dict, const char *key) _PDFIO_INTERNAL;

View File

@ -1266,7 +1266,9 @@ stream_write(pdfio_stream_t *st, // I - Stream
outbytes = bytes; outbytes = bytes;
} }
if (!_pdfioFileWrite(st->pdf, st->cbuffer, bytes)) // fprintf(stderr, "stream_write: bytes=%u, outbytes=%u\n", (unsigned)bytes, (unsigned)outbytes);
if (!_pdfioFileWrite(st->pdf, st->cbuffer, outbytes))
return (false); return (false);
if (bytes > outbytes) if (bytes > outbytes)