Skip to content

Commit

Permalink
[MSHARED-1445] Unix timestamps since the epoch are not subject to the…
Browse files Browse the repository at this point in the history
… boundary checks

This closes apache#73
  • Loading branch information
michael-o committed Oct 14, 2024
1 parent 62ac326 commit f756583
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/main/java/org/apache/maven/archiver/MavenArchiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,13 @@ public static Optional<Instant> parseBuildOutputTimestamp(String outputTimestamp

// 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
Expand Down
10 changes: 3 additions & 7 deletions src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1232,10 +1232,6 @@ void testParseOutputTimestamp() {

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()
Expand Down Expand Up @@ -1270,9 +1266,6 @@ void testEmptyParseOutputTimestampInstant(String value) {

@ParameterizedTest
@CsvSource({
"0,0",
"1,1",
"9,9",
"1570300662,1570300662",
"2147483648,2147483648",
"2019-10-05T18:37:42Z,1570300662",
Expand Down Expand Up @@ -1308,6 +1301,9 @@ void testThrownParseOutputTimestampInstant(String outputTimestamp) {
@ParameterizedTest
@ValueSource(
strings = {
"0",
"1",
"9",
"1980-01-01T00:00:01Z",
"2100-01-01T00:00Z",
"2100-02-28T23:59:59Z",
Expand Down

0 comments on commit f756583

Please sign in to comment.