Uploaded image for project: 'Apache Ozone'
  1. Apache Ozone
  2. HDDS-2784

Read to ByteBuffer uses wrong offset

    XMLWordPrintableJSON

Details

    Description

      OzoneFSInputStream#read(ByteBuffer) uses the target buffer's position for offsetting into the temporary array:

        public int read(ByteBuffer buf) throws IOException {
      
          int bufInitPos = buf.position();
          int readLen = Math.min(buf.remaining(), inputStream.available());
      
          byte[] readData = new byte[readLen];
          int bytesRead = inputStream.read(readData, bufInitPos, readLen);
          buf.put(readData);
      

      Given a buffer with capacity=10 and position=8, this results in the following:

      • readLen = 2 => readData.length = 2
      • bufInitPos = 8

      So inputStream reads 2 bytes and writes it into readData starting at offset 8, which results in an IndexOutOfBoundsException.

      offset should always be 0, since the temporary array is sized exactly for the length to read, and it has no extra data at the start.

      Attachments

        Issue Links

          Activity

            People

              adoroszlai Attila Doroszlai
              adoroszlai Attila Doroszlai
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m