Closed Bug 27022 Opened 25 years ago Closed 25 years ago

Files read through nsBufferedInputStream are truncated

Categories

(Core :: Networking, defect, P3)

x86
Linux
defect

Tracking

()

VERIFIED FIXED

People

(Reporter: mbp, Assigned: warrensomebody)

Details

(Whiteboard: [PDT+])

Files read through nsBufferedInputStream are truncated to mBufferSize.
If I try to read a large (text, html or other) file into the browser, I only get
the first 64K.
This happens with the latest (feb 8) source, but not with M13.

The problem seems to be a bug in nsBufferedInputStram::Fill() in the file
mozilla/netwerk/base/src/nsBufferedStreams.cpp
If the buffer is empty when Fill() is called, mFillPoint is not moved back to
zero. And under some circumstances this means that nothing is read into the
buffer. 
To fix it I changed 

    if (rem > 0) {
        // slide the remainder down to the start of the buffer
        // |<------------->|<--rem-->|<--->|
        // b               c         f     s
        nsCRT::memcpy(mBuffer, mBuffer + mCursor, rem);
        mBufferStartOffset += mCursor;    
        mFillPoint = rem;
        mCursor = 0;
    }

to the following:

    if (rem > 0) {
        // slide the remainder down to the start of the buffer
        // |<------------->|<--rem-->|<--->|
        // b               c         f     s
        nsCRT::memcpy(mBuffer, mBuffer + mCursor, rem);
        mBufferStartOffset += mCursor;
    }
    mFillPoint = rem;
    mCursor = 0;

This seems to work well here, at least.
I'll take this. 

Doug: Can you review this change too?

Jud: Could this be related to the data transfer problem you were seeing in the 
socket transport?
Assignee: gagan → warren
Keywords: beta1
Target Milestone: M14
quite possibly (rick has that bug now). let me know when you've got something 
and I'll test it.
nice find mbp@worldonline.dk.  warren, r=dougt.
Jud: Give this patch a try and see if it fixes the other problem you were 
seeing.
it may have helped, but we still bogg out. I'm noticing some event processing 
issues. If I give other windows attention while uploading, we seem to fall out 
of select and write some data :-/
scratch the event processing association comment, I'm tired. and I take back the 
"maybe" comment too. If I try to upload a 150k file, we get up to about 145k 
then stall. If I try to upload a 50k file, we get up to about 40k then stall.
Sounds like it's not flushing the last chunk in the buffer. If this is for 
input streams, then maybe we should just turn buffering off for now. We 
primarily determined the need for buffering for output streams. Input streams 
where a "bonus."
Whiteboard: [PDT+]
I think we need to pull mBufferStartOffset += mCursor; out of the if statement 
too, right? Otherwise the seek stuff gets thrown off.
I think you're right. "mBufferStartOffset += mCursor;" should also be moved. 
mbp -- muchos gracias for spotting this, and for your suggested fix!
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
verified:
Linux 2000021510
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.