This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 9be9ddb65a Add a safety against some invalid LZW compressions (missing 
EOI code).
9be9ddb65a is described below

commit 9be9ddb65ae97908cfd4c592dc03f8a425d6d259
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Mon Jul 4 12:44:10 2022 +0200

    Add a safety against some invalid LZW compressions (missing EOI code).
---
 .../src/main/java/org/apache/sis/internal/storage/inflater/LZW.java  | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git 
a/storage/sis-geotiff/src/main/java/org/apache/sis/internal/storage/inflater/LZW.java
 
b/storage/sis-geotiff/src/main/java/org/apache/sis/internal/storage/inflater/LZW.java
index e6b5b12757..f419866332 100644
--- 
a/storage/sis-geotiff/src/main/java/org/apache/sis/internal/storage/inflater/LZW.java
+++ 
b/storage/sis-geotiff/src/main/java/org/apache/sis/internal/storage/inflater/LZW.java
@@ -183,9 +183,10 @@ final class LZW extends CompressionChannel {
                 maximumIndex       = (1 << MIN_CODE_SIZE) - OFFSET_TO_MAXIMUM;
                 /*
                  * We should not have consecutive clear codes, but it is easy 
to check for safety.
-                 * The first valid code after `CLEAR_CODE` shall be a byte.
+                 * The first valid code after `CLEAR_CODE` shall be a byte. If 
we reached the end
+                 * of strip, the EOI code should be mandatory but appears to 
be sometime missing.
                  */
-                do code = (int) input.readBits(MIN_CODE_SIZE);              // 
GetNextCode()
+                do code = finished() ? EOI_CODE : (int) 
input.readBits(MIN_CODE_SIZE);      // GetNextCode()
                 while (code == CLEAR_CODE);
                 if (code == EOI_CODE) break;
                 if ((code & ~0xFF) != 0) {

Reply via email to