This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch maven-archiver-3.x
in repository https://gitbox.apache.org/repos/asf/maven-archiver.git
The following commit(s) were added to refs/heads/maven-archiver-3.x by this
push:
new 369127c [MSHARED-1445] Unix timestamps since the epoch are not
subject to the boundary checks
369127c is described below
commit 369127cd9b7eba79100100411d622b53308b9829
Author: Michael Osipov <[email protected]>
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 | 9 +++------
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/apache/maven/archiver/MavenArchiver.java
b/src/main/java/org/apache/maven/archiver/MavenArchiver.java
index 5b3e2f7..c818a46 100644
--- a/src/main/java/org/apache/maven/archiver/MavenArchiver.java
+++ b/src/main/java/org/apache/maven/archiver/MavenArchiver.java
@@ -758,7 +758,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 97850c5..72ab4e2 100644
--- a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
+++ b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
@@ -1342,9 +1342,6 @@ class MavenArchiverTest {
assertThat(parseBuildOutputTimestamp("1570300662").get().getEpochSecond())
.isEqualTo(1570300662L);
-
assertThat(parseBuildOutputTimestamp("0").get().getEpochSecond()).isZero();
-
assertThat(parseBuildOutputTimestamp("1").get().getEpochSecond()).isEqualTo(1L);
-
assertThat(parseBuildOutputTimestamp("2019-10-05T18:37:42Z").get().getEpochSecond())
.isEqualTo(1570300662L);
assertThat(parseBuildOutputTimestamp("2019-10-05T20:37:42+02:00").get().getEpochSecond())
@@ -1372,9 +1369,6 @@ class MavenArchiverTest {
@ParameterizedTest
@CsvSource({
- "0,0",
- "1,1",
- "9,9",
"1570300662,1570300662",
"2147483648,2147483648",
"2019-10-05T18:37:42Z,1570300662",
@@ -1410,6 +1404,9 @@ class MavenArchiverTest {
@ParameterizedTest
@ValueSource(
strings = {
+ "0",
+ "1",
+ "9",
"1980-01-01T00:00:01Z",
"2100-01-01T00:00Z",
"2100-02-28T23:59:59Z",