ant/0001-Fix-integer-overflow-when-parsing-SOURCE_DATE_EPOCH.patch

69 lines
2.7 KiB
Diff
Raw Normal View History

From 750924c556fbb0c431e983ec57befb9a7f070685 Mon Sep 17 00:00:00 2001
From: Marian Koncek <mkoncek@redhat.com>
Date: Fri, 3 Jun 2022 12:43:45 +0200
Subject: [PATCH] Fix integer overflow when parsing SOURCE_DATE_EPOCH
Upstream: https://github.com/apache/ant/pull/186/commits
---
.../org/apache/tools/ant/taskdefs/Tstamp.java | 2 +-
src/tests/antunit/taskdefs/tstamp-test.xml | 31 +++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/src/main/org/apache/tools/ant/taskdefs/Tstamp.java b/src/main/org/apache/tools/ant/taskdefs/Tstamp.java
index aa1034e..ca10efe 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Tstamp.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Tstamp.java
@@ -82,7 +82,7 @@ public class Tstamp extends Task {
try {
if (epoch != null) {
// Value of SOURCE_DATE_EPOCH will be an integer, representing seconds.
- d = new Date(Integer.parseInt(epoch) * 1000);
+ d = new Date(Long.parseLong(epoch) * 1000L);
log("Honouring environment variable " + ENV_SOURCE_DATE_EPOCH + " which has been set to " + epoch);
}
} catch(NumberFormatException e) {
diff --git a/src/tests/antunit/taskdefs/tstamp-test.xml b/src/tests/antunit/taskdefs/tstamp-test.xml
index 20c3227..1553d32 100644
--- a/src/tests/antunit/taskdefs/tstamp-test.xml
+++ b/src/tests/antunit/taskdefs/tstamp-test.xml
@@ -75,4 +75,35 @@ public class IsEpochIn1969Here implements Condition {
<!-- 'iso' overrides 'simple' -->
<au:assertPropertyEquals name="DSTAMP" value="19720417"/>
</target>
+
+ <target name="testSourceDateEpoch">
+ <mkdir dir="${input}"/>
+ <mkdir dir="${output}"/>
+ <echo file="${input}/TstampAntunitTest.java"><![CDATA[
+ import org.apache.tools.ant.*;
+ import org.apache.tools.ant.taskdefs.*;
+ public class TstampAntunitTest {
+ public static void main(String[] args) {
+ Task task = new Tstamp();
+ task.setProject(new Project());
+ task.execute();
+ String today = task.getProject().getProperty("TODAY");
+ System.out.println("TODAY is " + today);
+ }
+ }
+ ]]></echo>
+ <javac srcdir="${input}" destdir="${output}"/>
+ <local name="testout"/>
+ <java classname="TstampAntunitTest"
+ failonerror="true"
+ outputproperty="testout"
+ fork="true">
+ <classpath>
+ <pathelement location="${output}"/>
+ <pathelement path="${java.class.path}"/>
+ </classpath>
+ <env key="SOURCE_DATE_EPOCH" value="1650585600"/>
+ </java>
+ <au:assertEquals expected="TODAY is April 22 2022" actual="${testout}"/>
+ </target>
</project>
--
2.35.1