Revert "[libpng16] Revert ADLER32 error handling in pngrutil.c and pngpread.c."

This reverts commit 8c0c9e14afdd03610a9802eda4805a5f0d326375.

https://b.corp.google.com/u/1/issues/33057876

Change-Id: I7be19ecda436bf2ee931fd9b0d334b5a4362574c
diff --git a/README.android b/README.android
index 32fb665..f6062c6 100644
--- a/README.android
+++ b/README.android
@@ -21,7 +21,3 @@
     in contrib/intel/intel_sse.patch.
     The patch was applied using the following command:
     'patch -i contrib/intel/intel_sse.patch -p1'
-
-(5) Revert ADLER32 error handling to fix the infinite loop
-Cherry picked from upstream:
-https://github.com/glennrp/libpng/commit/d65a92b951079d315e17e20ba9e7b8423d19397e
diff --git a/pngpread.c b/pngpread.c
index 794352f..650ba1e 100644
--- a/pngpread.c
+++ b/pngpread.c
@@ -684,7 +684,12 @@
             png_warning(png_ptr, "Truncated compressed data in IDAT");
 
          else
-            png_error(png_ptr, "Decompression error in IDAT");
+         {
+            if (ret == Z_DATA_ERROR)
+               png_benign_error(png_ptr, "IDAT: ADLER32 checksum mismatch");
+            else
+               png_error(png_ptr, "Decompression error in IDAT");
+         }
 
          /* Skip the check on unprocessed input */
          return;
diff --git a/pngrutil.c b/pngrutil.c
index 3390367..fb5f5f0 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -4107,7 +4107,15 @@
          png_zstream_error(png_ptr, ret);
 
          if (output != NULL)
-            png_chunk_error(png_ptr, png_ptr->zstream.msg);
+         {
+            if(!strncmp(png_ptr->zstream.msg,"incorrect data check",20))
+            {
+               png_chunk_benign_error(png_ptr, "ADLER32 checksum mismatch");
+               continue;
+            }
+            else
+               png_chunk_error(png_ptr, png_ptr->zstream.msg);
+         }
 
          else /* checking */
          {