Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8066915

(fs) Files.newByteChannel opens directories for cases where subsequent reads may fail

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b43
    • Verification:
      Verified

      Backports

        Description


        On Unix/like systems it is currently possible to open a directory for read access but subsequent reads fail. It would be more desirable for the open to fail.

          Issue Links

            Activity

            Hide
            alanb Alan Bateman added a comment -
            Easier fixed by checking if the file is a directory after opening the file:

            -- old/src/java.base/unix/classes/sun/nio/fs/UnixChannelFactory.java 2014-12-08 13:04:17.512348430 +0000
            +++ new/src/java.base/unix/classes/sun/nio/fs/UnixChannelFactory.java 2014-12-08 13:04:17.356348430 +0000
            @@ -270,6 +270,22 @@
                         throw x;
                     }
             
            + // fail if the file is a directory
            + if (flags.read) {
            + UnixException exc = null;
            + try {
            + if (UnixFileAttributes.get(fd).isDirectory()) {
            + exc = new UnixException(EISDIR);
            + }
            + } catch (UnixException x) {
            + exc = x;
            + }
            + if (exc != null) {
            + close(fd);
            + throw exc;
            + }
            + }
            +
                     // unlink file immediately if delete on close. The spec is clear that
                     // an implementation cannot guarantee to unlink the correct file when
                     // replaced by an attacker after it is opened.
            Show
            alanb Alan Bateman added a comment - Easier fixed by checking if the file is a directory after opening the file: -- old/src/java.base/unix/classes/sun/nio/fs/UnixChannelFactory.java 2014-12-08 13:04:17.512348430 +0000 +++ new/src/java.base/unix/classes/sun/nio/fs/UnixChannelFactory.java 2014-12-08 13:04:17.356348430 +0000 @@ -270,6 +270,22 @@              throw x;          }   + // fail if the file is a directory + if (flags.read) { + UnixException exc = null; + try { + if (UnixFileAttributes.get(fd).isDirectory()) { + exc = new UnixException(EISDIR); + } + } catch (UnixException x) { + exc = x; + } + if (exc != null) { + close(fd); + throw exc; + } + } +          // unlink file immediately if delete on close. The spec is clear that          // an implementation cannot guarantee to unlink the correct file when          // replaced by an attacker after it is opened.
            Hide
            alanb Alan Bateman added a comment -
            There is a related issue on Windows in that the IOException that is thrown is AccessDeniedException. This is because Windows returns error 5 "Access Denied" for this case. The best we can do is react to this error and attempt to check if the file is a directory. This is something for another issue.
            Show
            alanb Alan Bateman added a comment - There is a related issue on Windows in that the IOException that is thrown is AccessDeniedException. This is because Windows returns error 5 "Access Denied" for this case. The best we can do is react to this error and attempt to check if the file is a directory. This is something for another issue.
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/e5b66323ae45
            User: alanb
            Date: 2014-12-10 15:07:46 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/e5b66323ae45 User: alanb Date: 2014-12-10 15:07:46 +0000
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/e5b66323ae45
            User: lana
            Date: 2014-12-17 21:52:48 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/e5b66323ae45 User: lana Date: 2014-12-17 21:52:48 +0000
            Hide
            bpb Brian Burkhalter added a comment -
            Discussion thread "Recent Java 9 commit (e5b66323ae45) breaks fsync on directory"
            http://mail.openjdk.java.net/pipermail/nio-dev/2015-January/002979.html
            Show
            bpb Brian Burkhalter added a comment - Discussion thread "Recent Java 9 commit (e5b66323ae45) breaks fsync on directory" http://mail.openjdk.java.net/pipermail/nio-dev/2015-January/002979.html

              People

              • Assignee:
                alanb Alan Bateman
                Reporter:
                alanb Alan Bateman
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: