Browse Source

Fix integer overflow when parsing SOURCE_DATE_EPOCH

This closes #186 pull request at github/apache/ant repo.
master
Mikolaj Izdebski Jaikiran Pai 3 years ago
parent
commit
babd1c4007
5 changed files with 41 additions and 1 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +4
    -0
      WHATSNEW
  3. +4
    -0
      contributors.xml
  4. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/Tstamp.java
  5. +31
    -0
      src/tests/antunit/taskdefs/tstamp-test.xml

+ 1
- 0
CONTRIBUTORS View File

@@ -309,6 +309,7 @@ Miha
Mike Davis
Mike Roberts
Mike Williams
Mikolaj Izdebski
Miroslav Zaťko
Mounir El Hajj
Nathan Beyer


+ 4
- 0
WHATSNEW View File

@@ -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:
--------------



+ 4
- 0
contributors.xml View File

@@ -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>


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/Tstamp.java View File

@@ -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) {


+ 31
- 0
src/tests/antunit/taskdefs/tstamp-test.xml View File

@@ -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>

Loading…
Cancel
Save