Open Bug 347660 Opened 20 years ago Updated 2 years ago

nsBufferedOutputStream::WriteSegments doesn't handle the reader returning zero

Categories

(Core :: Networking, defect, P5)

defect

Tracking

()

People

(Reporter: Biesinger, Unassigned)

References

()

Details

(Whiteboard: [necko-backlog])

Per http://lxr.mozilla.org/seamonkey/source/xpcom/io/nsIOutputStream.idl#60, the reader for writeSegments is allowed to return success and zero bytes. But, the buffered output stream does not handle that, it looks like it would go into an infinite loop in that case. This is a quite relevant case since when used via writeFrom, this would hang at EOF (when the input stream would return zero).
Whiteboard: [necko-backlog]
Severity: critical → normal
Priority: -- → P1
Priority: P1 → P3

Bulk-downgrade of unassigned, untouched DOM/Storage bug's priority.

If you have reason to believe, this is wrong, please write a comment and ni :jstutte.

Severity: normal → S4
Priority: P3 → P5

I think this bug may still be valid, but not sure how much of an issue it really is in practice.

https://searchfox.org/mozilla-central/rev/cb5faf5dd5176494302068c553da97b4d08aa339/netwerk/base/nsBufferedStreams.cpp#1052-1079

nsBufferedOutputStream::WriteSegments(nsReadSegmentFun reader, void* closure,
                                      uint32_t count, uint32_t* _retval) {
  *_retval = 0;
  nsresult rv;
  RecursiveMutexAutoLock lock(mBufferMutex);
  while (count > 0) {
    uint32_t left = std::min(count, mBufferSize - mCursor);
    if (left == 0) {
      rv = Flush();
      if (NS_FAILED(rv)) {
        return (*_retval > 0) ? NS_OK : rv;
      }

      continue;
    }

    uint32_t read = 0;
    rv = reader(this, closure, mBuffer + mCursor, *_retval, left, &read);

    if (NS_FAILED(rv)) {  // If we have read some data, return ok
      return (*_retval > 0) ? NS_OK : rv;
    }
    mCursor += read;
    *_retval += read;
    count -= read;
    mFillPoint = std::max(mFillPoint, mCursor);
  }
  return NS_OK;
You need to log in before you can comment on or make changes to this bug.