2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 19:08:59 +00:00

Bug fix: let EOF resolve literal token

Previously only whitespace and comments did it.  This fix is needed
for object streams whose last object is a literal (name, integer,
real, string) not terminated by space or newline.
This commit is contained in:
Jay Berkenbilt 2012-08-11 09:27:30 -04:00
parent 137dc7acb9
commit 29e9c34fe3
3 changed files with 27 additions and 15 deletions

View File

@ -1,3 +1,8 @@
2012-08-11 Jay Berkenbilt <ejb@ql.org>
* Bug fix: let EOF terminate a literal token as well as
whitespace or comments.
2012-07-31 Jay Berkenbilt <ejb@ql.org> 2012-07-31 Jay Berkenbilt <ejb@ql.org>
* 3.0.0: release * 3.0.0: release

View File

@ -434,22 +434,19 @@ QPDFTokenizer::presentCharacter(char ch)
void void
QPDFTokenizer::presentEOF() QPDFTokenizer::presentEOF()
{ {
switch (state) if (state == st_literal)
{ {
case st_token_ready: QTC::TC("qpdf", "QPDF_Tokenizer EOF reading appendable token");
case st_top: resolveLiteral();
// okay }
break; else if (state != st_token_ready)
{
case st_in_comment: QTC::TC("qpdf", "QPDF_Tokenizer EOF reading token");
state = st_top;
break;
default:
type = tt_bad; type = tt_bad;
error_message = "EOF while reading token"; error_message = "EOF while reading token";
state = st_token_ready;
} }
state = st_token_ready;
} }
bool bool
@ -480,14 +477,22 @@ QPDFTokenizer::readToken(PointerHolder<InputSource> input,
Token token; Token token;
bool unread_char; bool unread_char;
char char_to_unread; char char_to_unread;
bool presented_eof = false;
while (! getToken(token, unread_char, char_to_unread)) while (! getToken(token, unread_char, char_to_unread))
{ {
char ch; char ch;
if (input->read(&ch, 1) == 0) if (input->read(&ch, 1) == 0)
{ {
throw QPDFExc(qpdf_e_damaged_pdf, input->getName(), if (! presented_eof)
context, offset, {
"EOF while reading token"); presentEOF();
presented_eof = true;
}
else
{
throw std::logic_error(
"getToken returned false after presenting EOF");
}
} }
else else
{ {

View File

@ -238,3 +238,5 @@ QPDFWriter copy use_aes 1
QPDFObjectHandle indirect without context 0 QPDFObjectHandle indirect without context 0
QPDFObjectHandle trailing data in parse 0 QPDFObjectHandle trailing data in parse 0
qpdf pages encryption password 0 qpdf pages encryption password 0
QPDF_Tokenizer EOF reading token 0
QPDF_Tokenizer EOF reading appendable token 0