From 806922f643b05b50e423a7f16fc800dfd52ca8ef Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 3 Sep 2023 13:56:02 -0400 Subject: [PATCH] ascii85: ignore whitespace between ~ and > (fixes #973) --- ChangeLog | 3 +++ libqpdf/Pl_ASCII85Decoder.cc | 21 +++++++++++---------- libtests/qtest/ascii85.test | 8 +++++++- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2389afe4..f7adf320 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2023-09-03 Jay Berkenbilt + * ascii85 parser: ignore spaces everywhere including between ~ + and >. Fixes #973. + * Bug fix: with --pages, if one of the external files had warnings but the main file did not, the warning was previously not taken into consideration when determining the exit status. diff --git a/libqpdf/Pl_ASCII85Decoder.cc b/libqpdf/Pl_ASCII85Decoder.cc index fd36722a..aef8718d 100644 --- a/libqpdf/Pl_ASCII85Decoder.cc +++ b/libqpdf/Pl_ASCII85Decoder.cc @@ -19,6 +19,17 @@ Pl_ASCII85Decoder::write(unsigned char const* buf, size_t len) return; } for (size_t i = 0; i < len; ++i) { + switch (buf[i]) { + case ' ': + case '\f': + case '\v': + case '\t': + case '\r': + case '\n': + QTC::TC("libtests", "Pl_ASCII85Decoder ignore space"); + // ignore whitespace + continue; + } if (eod > 1) { break; } else if (eod == 1) { @@ -30,16 +41,6 @@ Pl_ASCII85Decoder::write(unsigned char const* buf, size_t len) } } else { switch (buf[i]) { - case ' ': - case '\f': - case '\v': - case '\t': - case '\r': - case '\n': - QTC::TC("libtests", "Pl_ASCII85Decoder ignore space"); - // ignore whitespace - break; - case '~': eod = 1; break; diff --git a/libtests/qtest/ascii85.test b/libtests/qtest/ascii85.test index 53977619..1843f8a5 100644 --- a/libtests/qtest/ascii85.test +++ b/libtests/qtest/ascii85.test @@ -20,4 +20,10 @@ $td->runtest("partial decode", $td->EXIT_STATUS => 0}, $td->NORMALIZE_NEWLINES); -$td->report(2); +$td->runtest("newline between ~ and >", + {$td->COMMAND => "echo '\@<5skEHbu7\$3~\n>' | ascii85"}, + {$td->STRING => "asdfqwer\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->report(3);