gettalong
gettalong

Reputation: 830

PDF stream encoded using FlateDecode with predictor and not enough data

Is it allowed that a stream that is encoded using FlateDecode with a PNG predictor has a last predictor row that doesn't have the same column width as all the other rows? I.e. it misses some data?

Imagine, for example, a stream that has already been decoded using the Flate algorithm, resulting in 105 bytes. And a predictor with the parameters <</Predictor 15 /Columns 10>>.

Since the stream has 105 bytes, the predictor can decode 10 full rows containing 10 columns each, and one row with only 5 columns, i.e. data for 5 columns is missing. Should the last row be decoded as a row with only 5 columns, or should the last 5 bytes be discarded, or is the stream as a whole just invalid?

I didn't find anything in the PDF specification but I came across two PDF files in the wild that have such streams.

Upvotes: 1

Views: 1146

Answers (1)

Mihai Iancu
Mihai Iancu

Reputation: 1828

It is up to you to decide how to deal with invalid streams, PDF specification does not handle invalid data.

For example we take all the data that can be decoded and the rest is padded with 0.

Upvotes: 2

Related Questions