diff --git a/pdf.c b/pdf.c index 9a1ce545caf3c3c42b1d36d421012c6a045981b5..9ad84b323b8a2fdf37d7cb7a002d25bb2c2ca2b4 100644 --- a/pdf.c +++ b/pdf.c @@ -710,9 +710,10 @@ init_parser(struct Env *aux) H_RULE(hdr_junk, VIOL(h_many1(h_butnot(h_ch_range(0, 255), objdef)), "Uncommented junk after header (severity=1)")); - H_RULE(tail, SEQ(body, h_optional(xr_td), startxr)); - // XXX the real world likes to omit 'startxr' from all but the - // last trailer. we should accept-and-warn in that case. + H_RULE(tail, SEQ(body, CHX(SEQ(h_optional(xr_td), startxr), + VIOL(SEQ(xr_td, OPT(SEQ(nl, KW("startxref"), nl, lws, nat, nl)), + OPT(nl), OPT(LIT("%%EOF")), OPT(nl)), + "Improper end of trailer - missing startxref and/or %%EOF (severity=5)")))); H_RULE(final_eof_junk, CHX(VIOL(SEQ(h_many1(nl), end), "Multiple newlines after final %%EOF (severity=4)"), VIOL(h_many1(h_butnot(h_ch_range(0, 255), LIT("%%EOF"))), "Data after final %%EOF (severity=7)"),