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)

Categories

(Core :: Graphics: ImageLib, defect)

x86
Linux
defect

Tracking

()

UNCONFIRMED

People

(Reporter: meunierrom1, Unassigned)

Details

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.14) 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:1.9.0.14) 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; do_CreateInstance("@mozilla.org/file/local;1",NS_GET_IID(nsILocalFile),getter_AddRefs(localImgFile)); localImgFile->InitWithNativePath(NS_LITERAL_CSTRING(/home/user/image.png)); 2. Create an instance of nsIFileInputStream nsCOMPtr<nsIFileInputStream> imgFileInputStream; do_CreateInstance("@@mozilla.org/network/file-input-stream;1",NS_GET_IID(nsIFileInputStream),getter_AddRefs(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; do_CreateInstance("@mozilla.org/mime;1",NS_GET_IID(nsIMIMEService),getter_AddRefs(mimeService)); nsCAutoString mimetype; mimeService->GetTypeFromURI(imageURL,mimetype); 4. Create an imgITools instance nsCOMPtr<imgITools> imgTool; do_CreateInstance("@mozilla.org/image/tools;1",NS_GET_IID(imgITools),getter_AddRefs(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:1.9.2.3) 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: http://picniche.com/toolbar/imagedeck/ Relevant file is content/utilities/backgroundapi.js
Bob: if you're crashing, please file your own bug w/ a stack report or bp- id https://developer.mozilla.org/En/How_to_get_a_stacktrace_for_a_bug_report
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.