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

michaelo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-archiver.git


The following commit(s) were added to refs/heads/master by this push:
     new f756583  [MSHARED-1445] Unix timestamps since the epoch are not 
subject to the boundary checks
f756583 is described below

commit f7565830c499a758c78a16fa024124113e1b713c
Author: Michael Osipov <micha...@apache.org>
AuthorDate: Mon Oct 14 22:54:48 2024 +0200

    [MSHARED-1445] Unix timestamps since the epoch are not subject to the 
boundary checks
    
    This closes #73
---
 src/main/java/org/apache/maven/archiver/MavenArchiver.java     |  8 +++++++-
 src/test/java/org/apache/maven/archiver/MavenArchiverTest.java | 10 +++-------
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/maven/archiver/MavenArchiver.java 
b/src/main/java/org/apache/maven/archiver/MavenArchiver.java
index 11656fc..6a6e446 100644
--- a/src/main/java/org/apache/maven/archiver/MavenArchiver.java
+++ b/src/main/java/org/apache/maven/archiver/MavenArchiver.java
@@ -695,7 +695,13 @@ public class MavenArchiver {
 
         // Number representing seconds since the epoch
         if (isNumeric(outputTimestamp)) {
-            return 
Optional.of(Instant.ofEpochSecond(Long.parseLong(outputTimestamp)));
+            final Instant date = 
Instant.ofEpochSecond(Long.parseLong(outputTimestamp));
+
+            if (date.isBefore(DATE_MIN) || date.isAfter(DATE_MAX)) {
+                throw new IllegalArgumentException(
+                        "'" + date + "' is not within the valid range " + 
DATE_MIN + " to " + DATE_MAX);
+            }
+            return Optional.of(date);
         }
 
         // no timestamp configured (1 character configuration is useful to 
override a full value during pom
diff --git a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java 
b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
index 70278e2..025f1bf 100644
--- a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
+++ b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
@@ -1232,10 +1232,6 @@ class MavenArchiverTest {
 
         
assertThat(MavenArchiver.parseBuildOutputTimestamp("1570300662").get().toEpochMilli())
                 .isEqualTo(1570300662000L);
-        
assertThat(MavenArchiver.parseBuildOutputTimestamp("0").get().toEpochMilli())
-                .isZero();
-        
assertThat(MavenArchiver.parseBuildOutputTimestamp("1").get().toEpochMilli())
-                .isEqualTo(1000L);
 
         
assertThat(MavenArchiver.parseBuildOutputTimestamp("2019-10-05T18:37:42Z")
                         .get()
@@ -1270,9 +1266,6 @@ class MavenArchiverTest {
 
     @ParameterizedTest
     @CsvSource({
-        "0,0",
-        "1,1",
-        "9,9",
         "1570300662,1570300662",
         "2147483648,2147483648",
         "2019-10-05T18:37:42Z,1570300662",
@@ -1308,6 +1301,9 @@ class MavenArchiverTest {
     @ParameterizedTest
     @ValueSource(
             strings = {
+                "0",
+                "1",
+                "9",
                 "1980-01-01T00:00:01Z",
                 "2100-01-01T00:00Z",
                 "2100-02-28T23:59:59Z",

Reply via email to