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

(fc) Infinite loop FileChannel.truncate

    Details

    • Subcomponent:
    • Resolved In Build:
      b84
    • Verification:
      Verified

      Backports

        Description

        FULL PRODUCT VERSION :


        A DESCRIPTION OF THE PROBLEM :
        sun.nio.ch.FileChannelImpl#truncate(long) has this loop
        do {
           rv = (int)position0(fd, p);
        } while ((rv == IOStatus.INTERRUPTED) && isOpen());

        Problem is that in cases where position0(fd, p) returns p, and it just happens that p is a long value that when cast to int becomes -3, then the loop here where never terminate since IOStatus.INTERRUPTED is -3 as well.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        package play;

        import java.io.File;
        import java.io.RandomAccessFile;
        import java.nio.ByteBuffer;
        import java.nio.channels.FileChannel;

        public class Play {
        public static void main(String[] args) throws Throwable {
        ByteBuffer zeroByte = ByteBuffer.wrap(new byte[1]);
        File file = File.createTempFile("whatever", null);
        try (RandomAccessFile raf = new RandomAccessFile(file, "rw")
        ) {
        FileChannel channel = raf.getChannel();
        channel.position(8589934589L + 1);
        channel.write(zeroByte);
        zeroByte.flip();
        channel.truncate(8589934589L);
        }
        }
        }

        and now the thread will be stuck in that loop within FIleChannelImpl as described


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        that the truncation works
        ACTUAL -
        the thread gets into an infinite loop and never returns

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        package play;

        import java.io.File;
        import java.io.RandomAccessFile;
        import java.nio.ByteBuffer;
        import java.nio.channels.FileChannel;

        public class Play {
        public static void main(String[] args) throws Throwable {
        ByteBuffer zeroByte = ByteBuffer.wrap(new byte[1]);
        File file = File.createTempFile("whatever", null);
        try (RandomAccessFile raf = new RandomAccessFile(file, "rw")
        ) {
        FileChannel channel = raf.getChannel();
        channel.position(8589934589L + 1);
        channel.write(zeroByte);
        zeroByte.flip();
        channel.truncate(8589934589L);
        }
        }
        }
        ---------- END SOURCE ----------

          Issue Links

            Activity

            webbuggrp Webbug Group created issue -
            igerasim Ivan Gerasimov made changes -
            Field Original Value New Value
            Assignee Ivan Gerasimov [ igerasim ]
            igerasim Ivan Gerasimov made changes -
            Project Java Incidents [ 10301 ] JDK [ 10100 ]
            Key JI-9024650 JDK-8137121
            Workflow JBS Incident Workflow [ 4851392 ] JBS Workflow [ 4851392 ]
            Component/s core-libs [ 10300 ]
            Component/s core-libs [ 10701 ]
            Affects Version/s 8u60 [ 16814 ]
            Affects Version/s 8u60 [ 16903 ]
            igerasim Ivan Gerasimov made changes -
            Subcomponent java.nio [ 499 ] java.nio [ 228 ]
            igerasim Ivan Gerasimov made changes -
            OS windows_8 [ 17083 ]
            igerasim Ivan Gerasimov made changes -
            CPU x86 [ 17004 ]
            igerasim Ivan Gerasimov made changes -
            Status New [ 10000 ] Open [ 1 ]
            igerasim Ivan Gerasimov made changes -
            Summary unsafe long->int casting leading to inifinite loop in sun.nio.ch.FileChannelImpl (ch) Infinite loop in sun.nio.ch.FileChannelImpl.truncate
            igerasim Ivan Gerasimov made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            Understanding Fix Understood [ 10001 ]
            alanb Alan Bateman made changes -
            Summary (ch) Infinite loop in sun.nio.ch.FileChannelImpl.truncate (fc) Infinite loop FileChannel.truncate
            igerasim Ivan Gerasimov made changes -
            Link This issue backported by JDK-8137189 [ JDK-8137189 ]
            hgupdate HG Updates made changes -
            Status In Progress [ 3 ] Resolved [ 5 ]
            Resolved In Build team [ 17324 ]
            Understanding Fix Understood [ 10001 ]
            Fix Version/s 9 [ 14949 ]
            Resolution Fixed [ 1 ]
            igerasim Ivan Gerasimov made changes -
            Link This issue backported by JDK-8137190 [ JDK-8137190 ]
            igerasim Ivan Gerasimov made changes -
            Link This issue relates to JDK-8137230 [ JDK-8137230 ]
            hgupdate HG Updates made changes -
            Resolved In Build team [ 17324 ] master [ 18256 ]
            hgupdate HG Updates made changes -
            Resolved In Build master [ 18256 ] b84 [ 17539 ]
            igerasim Ivan Gerasimov made changes -
            Labels webbug 6-na webbug
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8140918 [ JDK-8140918 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8142106 [ JDK-8142106 ]
            coffeys Sean Coffey made changes -
            Labels 6-na webbug 6-na release-note=no webbug
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8147251 [ JDK-8147251 ]
            sqetools SQE Tools made changes -
            Status Resolved [ 5 ] Closed [ 6 ]
            Verification Verified [ 17000 ]
            sqetools SQE Tools made changes -
            Labels 6-na release-note=no webbug 6-na autoverify release-note=no webbug

              People

              • Assignee:
                igerasim Ivan Gerasimov
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: