Bug 1207129

Summary: 'jar uf' changes file permissions unexpectedly
Product: Red Hat Enterprise Linux 7 Reporter: Piyush Bhoot <pbhoot>
Component: java-1.7.0-openjdkAssignee: Andrew John Hughes <ahughes>
Status: CLOSED ERRATA QA Contact: Lukáš Zachar <lzachar>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.2CC: dbhole, jvanek
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: java-1.7.0-openjdk-1.7.0.101-2.6.6.6.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-11-03 22:58:23 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1203710, 1297579, 1313485    

Description Piyush Bhoot 2015-03-30 09:59:03 UTC
Description of problem:	
'jar uf' changes file permissions unexpectedly


Version-Release number of selected component (if applicable):
java-1.7.0-openjdk-1.7.0.71-2.5.3.1.el7_0.x86_64
to  java version "1.7.0_75"


How reproducible:
Always

Steps to Reproduce:
1] On RHEL 7 install latest openjdk

$ jar -cvf /tmp/aa.jar /tmp/aa1
added manifest
adding: tmp/aa1(in = 7) (out= 6)(deflated 14%)
 
-bash-4.2$ ls -l /tmp/aa.jar
-rw-rw-r-- 1 alfbiwer users 453 Mar 27 14:24 /tmp/aa.jar
 $ jar -uvf /tmp/aa.jar /tmp/aa2
adding: tmp/aa2(in = 8) (out= 6)(deflated 25%)

$ ls -l /tmp/aa.jar
-rw------- 1 alfbiwer users 565 Mar 27 14:25 /tmp/aa.jar

Actual results:
File permissions change

Expected results:
File Permission should not change

Additional info:
Seems regression
https://bugs.openjdk.java.net/browse/JDK-7175845

Comment 3 Andrew John Hughes 2016-01-06 13:39:29 UTC
7.2 has shipped, so switching this to 7.3.

Comment 5 Andrew John Hughes 2016-06-29 14:36:51 UTC
It looks like 7175845 may have been regressed during a merge:

7175845: "jar uf" changes file permissions unexpectedly
Reviewed-by: sherman, alanb

diff -r cb2985085ab4 -r c735836c2355 src/share/classes/sun/tools/jar/Main.java
--- a/src/share/classes/sun/tools/jar/Main.java	Mon Jun 18 15:51:37 2012 -0700
+++ b/src/share/classes/sun/tools/jar/Main.java	Wed Jun 20 15:49:12 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -137,7 +137,7 @@
         File dir = file.getParentFile();
         if (dir == null)
             dir = new File(".");
-        return Files.createTempFile(dir.toPath(), "jartmp", null).toFile();
+        return File.createTempFile("jartmp", null, dir);
     }
 
     private boolean ok;

diff -u {icedtea7/jdk,jdk7/jdk}/src/share/classes/sun/tools/jar/Main.java
--- src/share/classes/sun/tools/jar/Main.java	2015-06-12 16:19:50.081013982 +0100
+++ ../../jdk7/jdk/src/share/classes/sun/tools/jar/Main.java	2016-04-11 15:39:35.505188051 +0100
@@ -138,7 +138,7 @@
         File dir = file.getParentFile();
         if (dir == null)
             dir = new File(".");
-        return Files.createTempFile(dir.toPath(), "jartmp", null).toFile();
+        return File.createTempFile("jartmp", null, dir);
     }
 
     private boolean ok;

Comment 6 Andrew John Hughes 2016-06-29 15:03:03 UTC
Confirmed:

Latest release:

$ /usr/lib/jvm/icedtea-7/bin/java UpdateJar
[OWNER_WRITE, OWNER_READ, OTHERS_READ, GROUP_READ] not equal to [OWNER_WRITE, OWNER_READ]
java.lang.Exception: Stack trace
	at java.lang.Thread.dumpStack(Thread.java:1365)
	at UpdateJar.fail(UpdateJar.java:75)
	at UpdateJar.fail(UpdateJar.java:76)
	at UpdateJar.equal(UpdateJar.java:81)
	at UpdateJar.realMain(UpdateJar.java:65)
	at UpdateJar.main(UpdateJar.java:83)

Passed = 0 failed = 1

Patched build:

$ /mnt/builder/icedtea7/j2sdk-image/bin/java UpdateJar

Passed = 1 failed = 0

Comment 7 Andrew John Hughes 2016-06-29 15:05:20 UTC
$ touch /tmp/aa1
$ /mnt/builder/icedtea7/j2sdk-image/bin/jar -cvf /tmp/aa.jar /tmp/aa1
added manifest
adding: tmp/aa1(in = 0) (out= 0)(stored 0%)
$ touch /tmp/aa2
$ /mnt/builder/icedtea7/j2sdk-image/bin/jar -uvf /tmp/aa.jar /tmp/aa2
adding: tmp/aa2(in = 0) (out= 0)(stored 0%)
$ ls -l /tmp/aa.jar
-rw-r--r-- 1 andrew users 527 Jun 29 16:04 /tmp/aa.jar

Comment 12 errata-xmlrpc 2016-11-03 22:58:23 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2016-2140.html