Commit dc92574c10f3e2516ec6445b88c5d584f40df4e5

Authored by Jay Berkenbilt
1 parent a9bdeeb0

Fix some pipelines to be safe if downstream write fails (fuzz issue 28262)

ChangeLog
  1 +2021-01-04 Jay Berkenbilt <ejb@ql.org>
  2 +
  3 + * Move getNext()->write() calls in some pipelines to ensure that
  4 + state gates properly reset even if the next pipeline's write
  5 + throws an exception (fuzz issue 28262).
  6 +
1 2021-01-03 Jay Berkenbilt <ejb@ql.org> 7 2021-01-03 Jay Berkenbilt <ejb@ql.org>
2 8
3 * Don't include -o nospace with zsh completion setup so file 9 * Don't include -o nospace with zsh completion setup so file
fuzz/qpdf_extra/28262.fuzz 0 → 100644
No preview for this file type
libqpdf/Pl_AES_PDF.cc
@@ -238,6 +238,6 @@ Pl_AES_PDF::flush(bool strip_padding) @@ -238,6 +238,6 @@ Pl_AES_PDF::flush(bool strip_padding)
238 } 238 }
239 } 239 }
240 } 240 }
241 - getNext()->write(this->outbuf, bytes);  
242 this->offset = 0; 241 this->offset = 0;
  242 + getNext()->write(this->outbuf, bytes);
243 } 243 }
libqpdf/Pl_ASCII85Decoder.cc
@@ -119,10 +119,13 @@ Pl_ASCII85Decoder::flush() @@ -119,10 +119,13 @@ Pl_ASCII85Decoder::flush()
119 119
120 QTC::TC("libtests", "Pl_ASCII85Decoder partial flush", 120 QTC::TC("libtests", "Pl_ASCII85Decoder partial flush",
121 (this->pos == 5) ? 0 : 1); 121 (this->pos == 5) ? 0 : 1);
122 - getNext()->write(outbuf, this->pos - 1);  
123 - 122 + // Reset before calling getNext()->write in case that throws an
  123 + // exception.
  124 + auto t = this->pos - 1;
124 this->pos = 0; 125 this->pos = 0;
125 memset(this->inbuf, 117, 5); 126 memset(this->inbuf, 117, 5);
  127 +
  128 + getNext()->write(outbuf, t);
126 } 129 }
127 130
128 void 131 void
libqpdf/Pl_ASCIIHexDecoder.cc
@@ -97,12 +97,14 @@ Pl_ASCIIHexDecoder::flush() @@ -97,12 +97,14 @@ Pl_ASCIIHexDecoder::flush()
97 97
98 QTC::TC("libtests", "Pl_ASCIIHexDecoder partial flush", 98 QTC::TC("libtests", "Pl_ASCIIHexDecoder partial flush",
99 (this->pos == 2) ? 0 : 1); 99 (this->pos == 2) ? 0 : 1);
100 - getNext()->write(&ch, 1);  
101 - 100 + // Reset before calling getNext()->write in case that throws an
  101 + // exception.
102 this->pos = 0; 102 this->pos = 0;
103 this->inbuf[0] = '0'; 103 this->inbuf[0] = '0';
104 this->inbuf[1] = '0'; 104 this->inbuf[1] = '0';
105 this->inbuf[2] = '\0'; 105 this->inbuf[2] = '\0';
  106 +
  107 + getNext()->write(&ch, 1);
106 } 108 }
107 109
108 void 110 void
libqpdf/Pl_Count.cc
@@ -27,8 +27,8 @@ Pl_Count::write(unsigned char* buf, size_t len) @@ -27,8 +27,8 @@ Pl_Count::write(unsigned char* buf, size_t len)
27 if (len) 27 if (len)
28 { 28 {
29 this->m->count += QIntC::to_offset(len); 29 this->m->count += QIntC::to_offset(len);
30 - getNext()->write(buf, len);  
31 this->m->last_char = buf[len - 1]; 30 this->m->last_char = buf[len - 1];
  31 + getNext()->write(buf, len);
32 } 32 }
33 } 33 }
34 34