sodonnel opened a new pull request, #10431:
URL: https://github.com/apache/ozone/pull/10431

   ## What changes were proposed in this pull request?
   
   There is potential for an NPE at stream shutdown in the StreamBlockReader:
   
   poll() explicitly returns null when future.isDone() is true (stream 
completed). However readFromQueue() uses the return value without a null check:
   
     // StreamingReader.readFromQueue(), line 455-459
     ByteBuffer readFromQueue() throws IOException {
         final ReadBlockResponseProto readBlock = poll();   // can return null
         final ByteString data = readBlock.getData();       // NPE!
   
   This fires in the normal shutdown path: after the server sends the last 
chunk and closes the stream, the next poll() call returns null and this line 
throws NullPointerException instead of letting the caller handle EOF gracefully.
   
   Fixing this, can then cause an infinite loop in StreamingReader.read() 
(lines 446-451)
   
   The inner read loop has no exit when readFromQueue() returns null or an 
empty buffer:
   
   
   ```
     while (true) {
         final ByteBuffer buf = readFromQueue();
         if (buf != null && buf.hasRemaining()) {
             return buf;     // only exit
         }
         // else: loop forever
     }
   ```
   
   This could happen when:
    * Stream ends: once Bug 1 is fixed so readFromQueue() can return null, this 
loop spins forever on null.
    * Full offset skip: readFromQueue() adjusts the buffer position by pos - 
blockOffset. If the entire response arrived before the current position (e.g. 
after a seek, or when reading near the end of a small block), the adjusted 
buffer has 0 remaining bytes. The loop spins indefinitely without requesting 
new data, because readBlock() is only called once before the loop starts.
   
   Note - this builds on #10430 and will need rebased after it goes in.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-15480
   
   ## How was this patch tested?
   
   Unit tests added to reproduce the problem and ensure the fix corrects them.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to