Skip to content

Commit 1967ae7

Browse files
committed
Tolerate missing LZW end-of-information marker
Some TIFF encoders (e.g., UK Environment Agency LiDAR DTM tiles) omit the LZW end-of-information code. Previously `LZWReader::read` returned UnexpectedEof on `NoProgress` even when that same call had already decoded valid pixel bytes — discarding them and failing the whole image. This change returns any output produced in a `NoProgress` call. A subsequent read that produces zero output still errors, so a genuinely truncated stream is still caught by `read_exact`. Matches the LZW portion of image-rs#386 (dropped upstream pending a wider decoder-API rework). Carried by madri until upstream lands an equivalent fix.
1 parent e41159c commit 1967ae7

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/decoder/stream.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,15 @@ impl<R: Read> Read for LZWReader<R> {
170170
}
171171
}
172172
Ok(weezl::LzwStatus::NoProgress) => {
173+
// Some TIFF encoders omit the LZW end-of-information code.
174+
// If this call produced output, return it; a subsequent read
175+
// with zero progress still errors, so genuinely short streams
176+
// are still caught by `read_exact` downstream.
177+
// See image-rs/image-tiff#386 (fix dropped upstream pending
178+
// a wider decoder-API rework).
179+
if result.consumed_out > 0 {
180+
return Ok(result.consumed_out);
181+
}
173182
return Err(io::Error::new(
174183
io::ErrorKind::UnexpectedEof,
175184
"no lzw end code found",

0 commit comments

Comments
 (0)