Commit f631542dae1aaf9101135ed660cd3ff1d08ed93c

Alexei Podtelezhnikov 2021-04-27T11:39:58

[lzw] Preserve decompression stack when relocating to heap. * src/lzw/ftzopen.c (ft_lzwstate_stack_grow): Copy stack when relocating to heap.

diff --git a/ChangeLog b/ChangeLog
index a1e66e0..5f61c1c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2021-04-27  Alexei Podtelezhnikov  <apodtele@gmail.com>
 
+	[lzw] Preserve decompression stack when relocating to heap.
+
+	* src/lzw/ftzopen.c (ft_lzwstate_stack_grow): Copy stack when
+	relocating to heap.
+
+2021-04-27  Alexei Podtelezhnikov  <apodtele@gmail.com>
+
 	* src/cid/cidgload.c (cid_load_glyph): Restore the glyph_length check.
 
 2021-04-27  Werner Lemberg  <wl@gnu.org>
diff --git a/src/lzw/ftzopen.c b/src/lzw/ftzopen.c
index 0c61af0..8b5b357 100644
--- a/src/lzw/ftzopen.c
+++ b/src/lzw/ftzopen.c
@@ -127,6 +127,7 @@
 
       new_size = new_size + ( new_size >> 1 ) + 4;
 
+      /* if relocating to heap */
       if ( state->stack == state->stack_0 )
       {
         state->stack = NULL;
@@ -142,9 +143,13 @@
           return -1;
       }
 
-      if ( FT_RENEW_ARRAY( state->stack, old_size, new_size ) )
+      if ( FT_QRENEW_ARRAY( state->stack, old_size, new_size ) )
         return -1;
 
+      /* if relocating to heap */
+      if ( old_size == 0 )
+        FT_MEM_COPY( state->stack, state->stack_0, FT_LZW_DEFAULT_STACK_SIZE );
+
       state->stack_size = new_size;
     }
     return 0;