File 2251-zip-Don-t-use-deprecated-zlib-crc32-functions.patch of Package erlang

From d09b5580a8ea3de5c4fbbf518d5bc99aa2d6df07 Mon Sep 17 00:00:00 2001
From: Wojtek Mach <wojtek@wojtekmach.pl>
Date: Tue, 17 Nov 2020 12:05:26 +0100
Subject: [PATCH 1/4] zip: Don't use deprecated zlib crc32 functions

---
 lib/stdlib/src/zip.erl | 81 +++++++++++++++++++++---------------------
 1 file changed, 41 insertions(+), 40 deletions(-)

diff --git a/lib/stdlib/src/zip.erl b/lib/stdlib/src/zip.erl
index 8f703d9d1a..a9bf8fe95a 100644
--- a/lib/stdlib/src/zip.erl
+++ b/lib/stdlib/src/zip.erl
@@ -910,22 +910,21 @@ put_z_file(_Method, Sz, Out, _F, Pos, _Input, _Output, _OpO, _Z, directory) ->
     {Out, Pos + Sz, 0};
 put_z_file(_Method, 0, Out, _F, Pos, _Input, _Output, _OpO, _Z, regular) ->
     {Out, Pos, 0};
-put_z_file(?STORED, UncompSize, Out0, F, Pos0, Input, Output, OpO, Z, regular) ->
+put_z_file(?STORED, UncompSize, Out0, F, Pos0, Input, Output, OpO, _Z, regular) ->
     In0 = [],
     In1 = Input({open, F, OpO -- [write]}, In0),
-    CRC0 = zlib:crc32(Z, <<>>),
     {Data, In2} = Input({read, UncompSize}, In1),
     Out1 = Output({write, Data}, Out0),
-    CRC = zlib:crc32(Z, CRC0, Data),
+    CRC = erlang:crc32(Data),
     Input(close, In2),
     {Out1, Pos0+erlang:iolist_size(Data), CRC};
 put_z_file(?DEFLATED, UncompSize, Out0, F, Pos0, Input, Output, OpO, Z, regular) ->
     In0 = [],
     In1 = Input({open, F, OpO -- [write]}, In0),
     ok = zlib:deflateInit(Z, default, deflated, -?MAX_WBITS, 8, default),
-    {Out1, Pos1} =
-	put_z_data_loop(UncompSize, In1, Out0, Pos0, Input, Output, Z),
-    CRC = zlib:crc32(Z),
+    CRC0 = 0,
+    {Out1, Pos1, CRC} =
+        put_z_data_loop(UncompSize, In1, Out0, Pos0, Input, Output, CRC0, Z),
     ok = zlib:deflateEnd(Z),
     Input(close, In1),
     {Out1, Pos1, CRC}.
@@ -935,19 +934,20 @@ get_sync(N, N) -> finish;
 get_sync(_, _) -> full.
 
 %% compress data
-put_z_data_loop(0, _In, Out, Pos, _Input, _Output, _Z) ->
-    {Out, Pos};
-put_z_data_loop(UncompSize, In0, Out0, Pos0, Input, Output, Z) ->
+put_z_data_loop(0, _In, Out, Pos, _Input, _Output, CRC0, _Z) ->
+    {Out, Pos, CRC0};
+put_z_data_loop(UncompSize, In0, Out0, Pos0, Input, Output, CRC0, Z) ->
     N = erlang:min(?WRITE_BLOCK_SIZE, UncompSize),
     case Input({read, N}, In0) of
-	{eof, _In1} ->
-	    {Out0, Pos0};
-	{Uncompressed, In1} ->
-	    Compressed = zlib:deflate(Z, Uncompressed, get_sync(N, UncompSize)),
-	    Sz = erlang:iolist_size(Compressed),
-	    Out1 = Output({write, Compressed}, Out0),
-	    put_z_data_loop(UncompSize - N, In1, Out1, Pos0 + Sz,
-			      Input, Output, Z)
+        {eof, _In1} ->
+            {Out0, Pos0};
+        {Uncompressed, In1} ->
+            CRC1 = erlang:crc32(CRC0, Uncompressed),
+            Compressed = zlib:deflate(Z, Uncompressed, get_sync(N, UncompSize)),
+            Sz = erlang:iolist_size(Compressed),
+            Out1 = Output({write, Compressed}, Out0),
+            put_z_data_loop(UncompSize - N, In1, Out1, Pos0 + Sz,
+                Input, Output, CRC1, Z)
     end.
 
 %% raw iterators over central dir
@@ -1534,45 +1534,46 @@ get_file_name_extra(FileNameLen, ExtraLen, B, GPFlag) ->
 get_z_data(?DEFLATED, In0, FileName, CompSize, Input, Output, OpO, Z) ->
     ok = zlib:inflateInit(Z, -?MAX_WBITS),
     Out0 = Output({open, FileName, [write | OpO]}, []),
-    {In1, Out1, UncompSize} = get_z_data_loop(CompSize, 0, In0, Out0, Input, Output, Z),
-    CRC = zlib:crc32(Z),
+    CRC0 = 0,
+    {In1, Out1, UncompSize, CRC} = get_z_data_loop(CompSize, 0, In0, Out0, Input, Output, CRC0, Z),
     ?CATCH zlib:inflateEnd(Z),
     Out2 = Output({close, FileName}, Out1),
     {Out2, In1, CRC, UncompSize};
-get_z_data(?STORED, In0, FileName, CompSize, Input, Output, OpO, Z) ->
+get_z_data(?STORED, In0, FileName, CompSize, Input, Output, OpO, _Z) ->
     Out0 = Output({open, FileName, [write | OpO]}, []),
-    CRC0 = zlib:crc32(Z, <<>>),
-    {In1, Out1, CRC} = copy_data_loop(CompSize, In0, Out0, Input, Output,
-				      CRC0, Z),
+    CRC0 = 0,
+    {In1, Out1, CRC} = copy_data_loop(CompSize, In0, Out0, Input, Output, CRC0),
     Out2 = Output({close, FileName}, Out1),
     {Out2, In1, CRC, CompSize};
 get_z_data(_, _, _, _, _, _, _, _) ->
     throw(bad_file_header).
 
-copy_data_loop(0, In, Out, _Input, _Output, CRC, _Z) ->
+copy_data_loop(0, In, Out, _Input, _Output, CRC) ->
     {In, Out, CRC};
-copy_data_loop(CompSize, In0, Out0, Input, Output, CRC0, Z) ->
+copy_data_loop(CompSize, In0, Out0, Input, Output, CRC0) ->
     N = erlang:min(?READ_BLOCK_SIZE, CompSize),
     case Input({read, N}, In0) of
-	{eof, In1} -> {Out0, In1};
-	{Uncompressed, In1} ->
-	    CRC1 = zlib:crc32(Z, CRC0, Uncompressed),
-	    Out1 = Output({write, Uncompressed}, Out0),
-	    copy_data_loop(CompSize-N, In1, Out1, Input, Output, CRC1, Z)
+        {eof, In1} ->
+            {Out0, In1};
+        {Uncompressed, In1} ->
+            CRC1 = erlang:crc32(CRC0, Uncompressed),
+            Out1 = Output({write, Uncompressed}, Out0),
+            copy_data_loop(CompSize-N, In1, Out1, Input, Output, CRC1)
     end.
 
-get_z_data_loop(0, UncompSize, In, Out, _Input, _Output, _Z) ->
-    {In, Out, UncompSize};
-get_z_data_loop(CompSize, UncompSize, In0, Out0, Input, Output, Z) ->
+get_z_data_loop(0, UncompSize, In, Out, _Input, _Output, CRC0, _Z) ->
+    {In, Out, UncompSize, CRC0};
+get_z_data_loop(CompSize, UncompSize, In0, Out0, Input, Output, CRC0, Z) ->
     N = erlang:min(?READ_BLOCK_SIZE, CompSize),
     case Input({read, N}, In0) of
-	{eof, In1} ->
-	    {Out0, In1};
-	{Compressed, In1} ->
-	    Uncompressed = zlib:inflate(Z, Compressed),
-	    Out1 = Output({write, Uncompressed}, Out0),
-	    get_z_data_loop(CompSize-N, UncompSize + iolist_size(Uncompressed),
-			    In1, Out1, Input, Output, Z)
+        {eof, In1} ->
+            {Out0, In1};
+        {Compressed, In1} ->
+            Uncompressed = zlib:inflate(Z, Compressed),
+            CRC1 = erlang:crc32(CRC0, Uncompressed),
+            Out1 = Output({write, Uncompressed}, Out0),
+            get_z_data_loop(CompSize-N, UncompSize + iolist_size(Uncompressed),
+                In1, Out1, Input, Output, CRC1, Z)
     end.
 
 
-- 
2.26.2

openSUSE Build Service is sponsored by