@@ -151,9 +151,9 @@ class ZipFileSystem extends FileSystem {
151
151
this .forceEnd64 = isTrue (env , "forceZIP64End" );
152
152
this .defaultCompressionMethod = getDefaultCompressionMethod (env );
153
153
this .supportPosix = isTrue (env , PROPERTY_POSIX );
154
- this .defaultOwner = initOwner (zfpath , env );
155
- this .defaultGroup = initGroup (zfpath , env );
156
- this .defaultPermissions = initPermissions (env );
154
+ this .defaultOwner = supportPosix ? initOwner (zfpath , env ) : null ;
155
+ this .defaultGroup = supportPosix ? initGroup (zfpath , env ) : null ;
156
+ this .defaultPermissions = supportPosix ? initPermissions (env ) : null ;
157
157
this .supportedFileAttributeViews = supportPosix ?
158
158
Set .of ("basic" , "posix" , "zip" ) : Set .of ("basic" , "zip" );
159
159
if (Files .notExists (zfpath )) {
@@ -1575,9 +1575,9 @@ private byte[] initCEN() throws IOException {
1575
1575
throw new ZipException ("invalid CEN header (bad header size)" );
1576
1576
}
1577
1577
IndexNode inode = new IndexNode (cen , pos , nlen );
1578
- if (hasDotOrDotDot ( inode .name )) {
1578
+ if (inode .pathHasDotOrDotDot ( )) {
1579
1579
throw new ZipException ("ZIP file can't be opened as a file system " +
1580
- "because an entry has a '.' or '..' element in its name" );
1580
+ "because entry \" " + inode . nameAsString () + " \" has a '.' or '..' element in its name" );
1581
1581
}
1582
1582
inodes .put (inode , inode );
1583
1583
if (zc .isUTF8 () || (flag & FLAG_USE_UTF8 ) != 0 ) {
@@ -1595,44 +1595,6 @@ private byte[] initCEN() throws IOException {
1595
1595
return cen ;
1596
1596
}
1597
1597
1598
- /**
1599
- * Check Inode.name to see if it includes a "." or ".." in the name array
1600
- * @param path the path as stored in Inode.name to verify
1601
- * @return true if the path contains a "." or ".." entry; false otherwise
1602
- */
1603
- private boolean hasDotOrDotDot (byte [] path ) {
1604
- // Inode.name always includes "/" in path[0]
1605
- assert path [0 ] == '/' ;
1606
- if (path .length == 1 ) {
1607
- return false ;
1608
- }
1609
- int index = 1 ;
1610
- while (index < path .length ) {
1611
- int starting = index ;
1612
- while (index < path .length && path [index ] != '/' ) {
1613
- index ++;
1614
- }
1615
- // Check the path snippet for a "." or ".."
1616
- if (isDotOrDotDotPath (path , starting , index )) {
1617
- return true ;
1618
- }
1619
- index ++;
1620
- }
1621
- return false ;
1622
- }
1623
-
1624
- /**
1625
- * Check the path to see if it includes a "." or ".."
1626
- * @param path the path to check
1627
- * @return true if the path contains a "." or ".." entry; false otherwise
1628
- */
1629
- private boolean isDotOrDotDotPath (byte [] path , int start , int index ) {
1630
- int pathLen = index - start ;
1631
- if ((pathLen == 1 && path [start ] == '.' ))
1632
- return true ;
1633
- return (pathLen == 2 && path [start ] == '.' ) && path [start + 1 ] == '.' ;
1634
- }
1635
-
1636
1598
private final void checkUTF8 (byte [] a ) throws ZipException {
1637
1599
try {
1638
1600
int end = a .length ;
@@ -2653,6 +2615,37 @@ boolean isDir() {
2653
2615
return isdir ;
2654
2616
}
2655
2617
2618
+ /**
2619
+ * Check name if it contains a "." or ".." path element
2620
+ * @return true if the path contains a "." or ".." entry; false otherwise
2621
+ */
2622
+ private boolean pathHasDotOrDotDot () {
2623
+ // name always includes "/" in path[0]
2624
+ assert name [0 ] == '/' ;
2625
+ if (name .length == 1 ) {
2626
+ return false ;
2627
+ }
2628
+ int index = 1 ;
2629
+ while (index < name .length ) {
2630
+ int start = index ;
2631
+ while (index < name .length && name [index ] != '/' ) {
2632
+ index ++;
2633
+ }
2634
+ if (name [start ] == '.' ) {
2635
+ int len = index - start ;
2636
+ if (len == 1 || (name [start + 1 ] == '.' && len == 2 )) {
2637
+ return true ;
2638
+ }
2639
+ }
2640
+ index ++;
2641
+ }
2642
+ return false ;
2643
+ }
2644
+
2645
+ protected String nameAsString () {
2646
+ return new String (name );
2647
+ }
2648
+
2656
2649
@ Override
2657
2650
public boolean equals (Object other ) {
2658
2651
if (!(other instanceof IndexNode )) {
@@ -2671,7 +2664,7 @@ public int hashCode() {
2671
2664
2672
2665
@ Override
2673
2666
public String toString () {
2674
- return new String ( name ) + (isdir ? " (dir)" : " " ) + ", index: " + pos ;
2667
+ return nameAsString ( ) + (isdir ? " (dir)" : " " ) + ", index: " + pos ;
2675
2668
}
2676
2669
}
2677
2670
@@ -3207,7 +3200,7 @@ private void readLocEXTT(ZipFileSystem zipfs) throws IOException {
3207
3200
public String toString () {
3208
3201
StringBuilder sb = new StringBuilder (1024 );
3209
3202
Formatter fm = new Formatter (sb );
3210
- fm .format (" name : %s%n" , new String ( name ));
3203
+ fm .format (" name : %s%n" , nameAsString ( ));
3211
3204
fm .format (" creationTime : %tc%n" , creationTime ().toMillis ());
3212
3205
fm .format (" lastAccessTime : %tc%n" , lastAccessTime ().toMillis ());
3213
3206
fm .format (" lastModifiedTime: %tc%n" , lastModifiedTime ().toMillis ());
0 commit comments