Fix integer overflow when parsing SOURCE_DATE_EPOCH

This commit is contained in:
Marian Koncek 2022-06-03 12:50:56 +02:00
parent 1ed56aad68
commit bf3e96b4cf
2 changed files with 74 additions and 1 deletions

View File

@ -0,0 +1,68 @@
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

View File

@ -34,7 +34,7 @@
Name: ant Name: ant
Version: 1.10.12 Version: 1.10.12
Release: 4%{?dist} Release: 5%{?dist}
Summary: Java build tool Summary: Java build tool
Summary(it): Tool per la compilazione di programmi java Summary(it): Tool per la compilazione di programmi java
Summary(fr): Outil de compilation pour java Summary(fr): Outil de compilation pour java
@ -49,6 +49,7 @@ Source2: apache-ant-1.8.ant.conf
Source3: ant.asciidoc Source3: ant.asciidoc
Patch0: %{name}-build.xml.patch Patch0: %{name}-build.xml.patch
Patch1: 0001-Fix-integer-overflow-when-parsing-SOURCE_DATE_EPOCH.patch
BuildRequires: asciidoc BuildRequires: asciidoc
BuildRequires: xmlto BuildRequires: xmlto
@ -328,6 +329,7 @@ Javadoc pour %{name}.
%prep %prep
%setup -q -n apache-ant-%{version} %setup -q -n apache-ant-%{version}
%patch0 -p0 %patch0 -p0
%patch1 -p1
# clean jar files # clean jar files
find . -name "*.jar" | xargs -t rm find . -name "*.jar" | xargs -t rm
@ -640,6 +642,9 @@ LC_ALL=C.UTF-8 %{ant} test
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
%changelog %changelog
* Fri Jun 03 2022 Marian Koncek <mkoncek@redhat.com> - 1.10.12-5
- Fix integer overflow when parsing SOURCE_DATE_EPOCH
* Fri Apr 22 2022 Mikolaj Izdebski <mizdebsk@redhat.com> - 1.10.12-4 * Fri Apr 22 2022 Mikolaj Izdebski <mizdebsk@redhat.com> - 1.10.12-4
- Fix FTBFS with JUnit 5.8.x - Fix FTBFS with JUnit 5.8.x