Skip to content

Commit 369127c

Browse files
committed
[MSHARED-1445] Unix timestamps since the epoch are not subject to the boundary checks
This closes #73
1 parent 7d48b4b commit 369127c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/main/java/org/apache/maven/archiver/MavenArchiver.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,13 @@ public static Optional<Instant> parseBuildOutputTimestamp(String outputTimestamp
758758

759759
// Number representing seconds since the epoch
760760
if (isNumeric(outputTimestamp)) {
761-
return Optional.of(Instant.ofEpochSecond(Long.parseLong(outputTimestamp)));
761+
final Instant date = Instant.ofEpochSecond(Long.parseLong(outputTimestamp));
762+
763+
if (date.isBefore(DATE_MIN) || date.isAfter(DATE_MAX)) {
764+
throw new IllegalArgumentException(
765+
"'" + date + "' is not within the valid range " + DATE_MIN + " to " + DATE_MAX);
766+
}
767+
return Optional.of(date);
762768
}
763769

764770
// no timestamp configured (1 character configuration is useful to override a full value during pom

src/test/java/org/apache/maven/archiver/MavenArchiverTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,9 +1342,6 @@ void testParseOutputTimestamp() {
13421342

13431343
assertThat(parseBuildOutputTimestamp("1570300662").get().getEpochSecond())
13441344
.isEqualTo(1570300662L);
1345-
assertThat(parseBuildOutputTimestamp("0").get().getEpochSecond()).isZero();
1346-
assertThat(parseBuildOutputTimestamp("1").get().getEpochSecond()).isEqualTo(1L);
1347-
13481345
assertThat(parseBuildOutputTimestamp("2019-10-05T18:37:42Z").get().getEpochSecond())
13491346
.isEqualTo(1570300662L);
13501347
assertThat(parseBuildOutputTimestamp("2019-10-05T20:37:42+02:00").get().getEpochSecond())
@@ -1372,9 +1369,6 @@ void testEmptyParseOutputTimestampInstant(String value) {
13721369

13731370
@ParameterizedTest
13741371
@CsvSource({
1375-
"0,0",
1376-
"1,1",
1377-
"9,9",
13781372
"1570300662,1570300662",
13791373
"2147483648,2147483648",
13801374
"2019-10-05T18:37:42Z,1570300662",
@@ -1410,6 +1404,9 @@ void testThrownParseOutputTimestampInstant(String outputTimestamp) {
14101404
@ParameterizedTest
14111405
@ValueSource(
14121406
strings = {
1407+
"0",
1408+
"1",
1409+
"9",
14131410
"1980-01-01T00:00:01Z",
14141411
"2100-01-01T00:00Z",
14151412
"2100-02-28T23:59:59Z",

0 commit comments

Comments
 (0)