Open Bug 545673 Opened 14 years ago Updated 2 years ago

NS_InputStreamIsBuffered should initialize count or TestInputStream should set the count to zero

Categories

(Core :: XPCOM, defect)

1.9.2 Branch
x86
Windows 7
defect

Tracking

()

People

(Reporter: johnjbarton, Unassigned)

Details

Attachments

(1 file, 1 obsolete file)

I have built FF 3.6 with DEBUG and I am trying to get Chromebug+Firebug to run on it without asserts.

I assert here:
---
     nsresult rv = tee->mWriter(in, tee->mClosure, fromSegment, offset, count, writeCount);
    if (NS_FAILED(rv) || (*writeCount == 0)) {
        NS_ASSERTION((NS_FAILED(rv) ? (*writeCount == 0) : PR_TRUE),
                "writer returned an error with non-zero writeCount");
        return rv;
    }
---
in nsInputStreamTee.cpp. The reason is that mWriter is
---
static NS_METHOD
TestInputStream(nsIInputStream *inStr,
                void *closure,
                const char *buffer,
                PRUint32 offset,
                PRUint32 count,
                PRUint32 *countWritten)
{
    PRBool *result = static_cast<PRBool *>(closure);
    *result = PR_TRUE;
    return NS_ERROR_ABORT;  // don't call me anymore
}
---
The rv will be NS_ERROR_ABORT, but the writeCount will be what ever garbage value happened to be in that location? 

There seems to be two ways to fix this.

1) set writeCount to zero in TestInputStream
http://mxr.mozilla.org/mozilla1.9.2/source/xpcom/io/nsStreamUtils.cpp#695
or
2) initialize 'n' to zero in
http://mxr.mozilla.org/mozilla1.9.2/source/xpcom/io/nsStreamUtils.cpp#702

I think both should be done.
Or the assert should be fixed to not assert bogus things about out params of functions that return error?
Well, the point of the assert is to catch callees who want to consume some data of the stream but then return an error. That doesn't seem entirely unreasonable, and also, this is not an xpcom function - just a C++ callback that happens to be defined in IDL.

I think 2) should be done, 1) doesn't seem necessary to me.
Attached patch (trivial) patch for 1.9.2 (obsolete) — Splinter Review
I've been running my local copy of FF 3.6 with this patch. WFM ;-)
Attachment #426907 - Attachment is patch: true
Attachment #426907 - Attachment mime type: application/octet-stream → text/plain
I'm sorry, I didn't read comment 0 carefully enough when I said 2) should be done. What I meant was that nsInputStreamTee::WriteSegmentFun should initialize *writeCount before calling mWriter (not nsStreamUtils)
per comment 4, a refreshed patch
Attachment #426907 - Attachment is obsolete: true
I guess I need to do something to cause this to move forward, but I don't know what.

Nathan, could you check whether this still makes sense (I suspect it does) and get it landed if so?

Flags: needinfo?(nfroyd)
Flags: needinfo?(froydnj+bz)
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: