diff options
author | Jay Berkenbilt <ejb@ql.org> | 2021-01-04 17:55:28 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2021-01-04 21:17:35 +0100 |
commit | dc92574c10f3e2516ec6445b88c5d584f40df4e5 (patch) | |
tree | 221eca0c948b2a19d7735027e514459694fca7dd /libqpdf | |
parent | a9bdeeb0e0059cf702f63c04affbcb56ecc8a29e (diff) | |
download | qpdf-dc92574c10f3e2516ec6445b88c5d584f40df4e5.tar.zst |
Fix some pipelines to be safe if downstream write fails (fuzz issue 28262)
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/Pl_AES_PDF.cc | 2 | ||||
-rw-r--r-- | libqpdf/Pl_ASCII85Decoder.cc | 7 | ||||
-rw-r--r-- | libqpdf/Pl_ASCIIHexDecoder.cc | 6 | ||||
-rw-r--r-- | libqpdf/Pl_Count.cc | 2 |
4 files changed, 11 insertions, 6 deletions
diff --git a/libqpdf/Pl_AES_PDF.cc b/libqpdf/Pl_AES_PDF.cc index 18cf3a4d..2865f804 100644 --- a/libqpdf/Pl_AES_PDF.cc +++ b/libqpdf/Pl_AES_PDF.cc @@ -238,6 +238,6 @@ Pl_AES_PDF::flush(bool strip_padding) } } } - getNext()->write(this->outbuf, bytes); this->offset = 0; + getNext()->write(this->outbuf, bytes); } diff --git a/libqpdf/Pl_ASCII85Decoder.cc b/libqpdf/Pl_ASCII85Decoder.cc index b8df3e87..9d9f6704 100644 --- a/libqpdf/Pl_ASCII85Decoder.cc +++ b/libqpdf/Pl_ASCII85Decoder.cc @@ -119,10 +119,13 @@ Pl_ASCII85Decoder::flush() QTC::TC("libtests", "Pl_ASCII85Decoder partial flush", (this->pos == 5) ? 0 : 1); - getNext()->write(outbuf, this->pos - 1); - + // Reset before calling getNext()->write in case that throws an + // exception. + auto t = this->pos - 1; this->pos = 0; memset(this->inbuf, 117, 5); + + getNext()->write(outbuf, t); } void diff --git a/libqpdf/Pl_ASCIIHexDecoder.cc b/libqpdf/Pl_ASCIIHexDecoder.cc index f20a9769..7845268e 100644 --- a/libqpdf/Pl_ASCIIHexDecoder.cc +++ b/libqpdf/Pl_ASCIIHexDecoder.cc @@ -97,12 +97,14 @@ Pl_ASCIIHexDecoder::flush() QTC::TC("libtests", "Pl_ASCIIHexDecoder partial flush", (this->pos == 2) ? 0 : 1); - getNext()->write(&ch, 1); - + // Reset before calling getNext()->write in case that throws an + // exception. this->pos = 0; this->inbuf[0] = '0'; this->inbuf[1] = '0'; this->inbuf[2] = '\0'; + + getNext()->write(&ch, 1); } void diff --git a/libqpdf/Pl_Count.cc b/libqpdf/Pl_Count.cc index 8077092a..c35619b8 100644 --- a/libqpdf/Pl_Count.cc +++ b/libqpdf/Pl_Count.cc @@ -27,8 +27,8 @@ Pl_Count::write(unsigned char* buf, size_t len) if (len) { this->m->count += QIntC::to_offset(len); - getNext()->write(buf, len); this->m->last_char = buf[len - 1]; + getNext()->write(buf, len); } } |