From: pmqs <pmqs@cpan.org>
Date: Sat, 25 Oct 2025 19:50:08 +0100
Subject: Enhance _dosToUnixTime to handle zero and invalid datetime values;
 add tests for edge cases. Fixes #65

(Backported for Debian by Niko Tyni)

Origin: backport, https://github.com/pmqs/IO-Compress/commit/fd28c1d2374eee9811f6d0c5bddc0957abdf1da8
Bug: https://github.com/pmqs/IO-Compress/issues/65
Bug-Debian: https://bugs.debian.org/1138863
---
 MANIFEST                                    |   2 ++
 cpan/IO-Compress/lib/IO/Uncompress/Unzip.pm |  16 ++++++++++++++--
 cpan/IO-Compress/t/files/time-invalid.zip   | Bin 0 -> 122 bytes
 cpan/IO-Compress/t/files/time-zero.zip      | Bin 0 -> 122 bytes
 4 files changed, 16 insertions(+), 2 deletions(-)
 create mode 100644 cpan/IO-Compress/t/files/time-invalid.zip
 create mode 100644 cpan/IO-Compress/t/files/time-zero.zip

diff --git a/MANIFEST b/MANIFEST
index 6f8c3f9..02fefc5 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1401,6 +1401,8 @@ cpan/IO-Compress/t/files/jar.zip			IO-Compress
 cpan/IO-Compress/t/files/meta.xml			IO-Compress
 cpan/IO-Compress/t/files/test.ods			IO-Compress
 cpan/IO-Compress/t/files/testfile1.odt			IO-Compress
+cpan/IO-Compress/t/files/time-invalid.zip		IO-Compress
+cpan/IO-Compress/t/files/time-zero.zip			IO-Compress
 cpan/IO-Compress/t/globmapper.t				IO::Compress
 cpan/IO-Socket-IP/.editorconfig				IO-Socket-IP
 cpan/IO-Socket-IP/lib/IO/Socket/IP.pm			IO::Socket::IP
diff --git a/cpan/IO-Compress/lib/IO/Uncompress/Unzip.pm b/cpan/IO-Compress/lib/IO/Uncompress/Unzip.pm
index 6dad364..802ee3c 100644
--- a/cpan/IO-Compress/lib/IO/Uncompress/Unzip.pm
+++ b/cpan/IO-Compress/lib/IO/Uncompress/Unzip.pm
@@ -802,7 +802,14 @@ sub filterUncompressed
 # from Archive::Zip & info-zip
 sub _dosToUnixTime
 {
+    # Returns zero when $dt is already zero or it doesn't expand to a value that Time::Local::timelocal()
+    # can handle.
+
 	my $dt = shift;
+    # warn "_dosToUnixTime dt=[$dt]\n";
+
+    # some zip files don't populate the datetime field at all
+    return 0 if ! $dt;
 
 	my $year = ( ( $dt >> 25 ) & 0x7f ) + 80;
 	my $mon  = ( ( $dt >> 21 ) & 0x0f ) - 1;
@@ -813,10 +820,15 @@ sub _dosToUnixTime
 	my $sec  = ( ( $dt << 1 ) & 0x3e );
 
     use Time::Local ;
-    my $time_t = Time::Local::timelocal( $sec, $min, $hour, $mday, $mon, $year);
+
+    my $time_t ;
+    # wrap in an eval to catch out of range errors
+    eval {
+        $time_t = Time::Local::timelocal( $sec, $min, $hour, $mday, $mon, $year);
+    } ;
+
     return 0 if ! defined $time_t;
     return $time_t;
-
 }
 
 #sub scanCentralDirectory
diff --git a/cpan/IO-Compress/t/files/time-invalid.zip b/cpan/IO-Compress/t/files/time-invalid.zip
new file mode 100644
index 0000000..ef8f99d
--- /dev/null
+++ b/cpan/IO-Compress/t/files/time-invalid.zip
@@ -0,0 +1,4 @@
+PK
+     ???? 0:6      	   hello.txthello
+PK
+     ???? 0:6      	          ??    hello.txtPK      7   -     
\ No newline at end of file
diff --git a/cpan/IO-Compress/t/files/time-zero.zip b/cpan/IO-Compress/t/files/time-zero.zip
new file mode 100644
index 0000000..cf6eeb4
--- /dev/null
+++ b/cpan/IO-Compress/t/files/time-zero.zip
@@ -0,0 +1,4 @@
+PK
+          0:6      	   hello.txthello
+PK
+          0:6      	          ??    hello.txtPK      7   -     
\ No newline at end of file
