Open Bug 527007 Opened 15 years ago Updated 2 years ago

imgITools::DecodeImageData(...) doesn't support unbuffered streams (such as nsIFileInputStream), must use nsIBufferedInputStream (in nsIBufferedStreams.h)


(Core :: Graphics: ImageLib, defect)






(Reporter: meunierrom1, Unassigned)


User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/2009090216 Ubuntu/9.04 (jaunty) Firefox/3.0.13 XPCOMViewer/0.9a
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/2009090216 Ubuntu/9.04 (jaunty) Firefox/3.0.13 XPCOMViewer/0.9a

The DecodeImageData(nsIInputStream* aInStr,const nsACString& aMimeType,imgIContainer **aContainer) function in the imgITools interface (located in imglib2 in the xulrunner-sdk) returns NS_NOT_IMPLEMENTED (error code 80004001) when the nsIInputStream is NOT a buffered stream. That's why you cannot use nsIFileInputStream.

Reproducible: Always

Steps to Reproduce:
Inside an XPCOM component try this:

1.Create an instance of nsILocalFile which points to an image file (e.g. /home/user/image.png)
nsCOMPtr<nsILocalFile> localImgFile;

2. Create an instance of nsIFileInputStream
nsCOMPtr<nsIFileInputStream> imgFileInputStream;

3. Initialize this nsIFileInputStream whith the file
imgFileInputStream->Init(localImgFile, PR_RDWR,PR_IRWXO,nsIFileInputStream::REOPEN_ON_REWIND);

5. Get the mime type of the stream by using the nsIIOService and the nsIURI created with the image path, and finally the nsIMIMEService
nsCOMPtr<nsIURI> imageURL;
ioService->NewURI(path, NULL, NULL, getter_AddRefs(imageURL));
nsCOMPtr<nsIMIMEService> mimeService;
nsCAutoString mimetype;												mimeService->GetTypeFromURI(imageURL,mimetype);

4. Create an imgITools instance
nsCOMPtr<imgITools> imgTool;

5. Last step, decode the data from the stream
nsCOMPtr<imgIContainer> imgContainer;
nsresult rv;
rv=imgTool->DecodeImageData(imgStream,mimetype, getter_AddRefs(imgContainer)) ;
printf("failed decoding data: %x\n", rv);

Actual Results:  
printf returns 80004001 (i.e. NS_NOT_IMPLEMENTED) and the imgIContainer instance is still empty

Expected Results:  
DecodeImageData() should have returned an imgIContainer containing the image data
Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20100401 Firefox/3.6.3
On ubuntu 9.04

I'm seeing similar behaviour calling from js in my extension. 
But I'm using a nsIBufferedInputStream, and though instead of returning NS_NOT_IMPLEMENTED, it is causing firefox to either freeze or crash. It only seems to be a problem for images of a large file size (>1MB), though does occasionally happen for smaller images.

You can see the problem in action in my extension here:
Relevant file is content/utilities/backgroundapi.js
Bob: if you're crashing, please file your own bug w/ a stack report or bp- id
Component: XPCOM → ImageLib
QA Contact: xpcom → imagelib
Severity: minor → S4
You need to log in before you can comment on or make changes to this bug.