You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by ja...@apache.org on 2022/05/21 02:13:51 UTC

[ant] branch master updated: Fix integer overflow when parsing SOURCE_DATE_EPOCH

This is an automated email from the ASF dual-hosted git repository.

jaikiran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git


The following commit(s) were added to refs/heads/master by this push:
     new babd1c400 Fix integer overflow when parsing SOURCE_DATE_EPOCH
babd1c400 is described below

commit babd1c4007b5d1afc9e4e0744455fbdd6b85e88d
Author: Mikolaj Izdebski <mi...@redhat.com>
AuthorDate: Sat Apr 23 00:12:11 2022 +0200

    Fix integer overflow when parsing SOURCE_DATE_EPOCH
    
    This closes #186 pull request at github/apache/ant repo.
---
 CONTRIBUTORS                                       |  1 +
 WHATSNEW                                           |  4 +++
 contributors.xml                                   |  4 +++
 src/main/org/apache/tools/ant/taskdefs/Tstamp.java |  2 +-
 src/tests/antunit/taskdefs/tstamp-test.xml         | 31 ++++++++++++++++++++++
 5 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index e721b2ffe..708f503cc 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -309,6 +309,7 @@ Miha
 Mike Davis
 Mike Roberts
 Mike Williams
+Mikolaj Izdebski
 Miroslav Zaťko
 Mounir El Hajj
 Nathan Beyer
diff --git a/WHATSNEW b/WHATSNEW
index b6476f61b..67c8f001a 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -25,6 +25,10 @@ Fixed bugs:
    timestamps of files transferred recursively from a server.
    Bugzilla Report 66001
 
+ * tstamp task would in certain cases parse the SOURCE_DATE_EPOCH environment variable
+   value to an incorrect date. This has now been fixed.
+   Github Pull Request #186
+
 Other changes:
 --------------
 
diff --git a/contributors.xml b/contributors.xml
index f0f5197c7..ddc55ecc8 100644
--- a/contributors.xml
+++ b/contributors.xml
@@ -1280,6 +1280,10 @@
     <first>Mike</first>
     <last>Williams</last>
   </name>
+  <name>
+    <first>Mikolaj</first>
+    <last>Izdebski</last>
+  </name>
   <name>
     <first>Miroslav</first>
     <last>Zaťko</last>
diff --git a/src/main/org/apache/tools/ant/taskdefs/Tstamp.java b/src/main/org/apache/tools/ant/taskdefs/Tstamp.java
index aa1034eae..ca10efe00 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 20c322762..1553d32ee 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>