Skip to content

Commit

Permalink
handle LZW decompression edge case (tlnagy#148)
Browse files Browse the repository at this point in the history
* handle LZW decompression edge case

* better

* add test

---------

Co-authored-by: Tamas Nagy <[email protected]>
  • Loading branch information
chrstphrbrns and tlnagy authored Jan 22, 2024
1 parent 6bfae1c commit 24605fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/compression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,14 @@ function lzw_decode!(io, arr)
end
end

if table_count == 511
codesize = 10
elseif table_count == 1023
codesize = 11
elseif table_count == 2047
codesize = 12
if out_position < output_size
if table_count == 511
codesize = 10
elseif table_count == 1023
codesize = 11
elseif table_count == 2047
codesize = 12
end
end
end

Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,8 @@ end
encoded = get_example("shapes_lzw_predictor3.tif")
@test TiffImages.load(original) == TiffImages.load(encoded)
end

@testset "Issue #148" begin
im = get_example("earthlab.tif")
@test size(TiffImages.load(im)) == (2400, 2400) # no error
end

0 comments on commit 24605fa

Please sign in to comment.