ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Dcraw 1.461 plugin hangs in FindStreamFormat
 New Topic  Reply to Topic
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

goobit

11 Posts

Posted - May 18 2014 :  05:08:16  Show Profile  Reply
Hi.

I have a "colorpicker.cur" file that ImageEn can't load as ioCUR file format. But this is not a problem for me. Problem that when dcraw plugin loaded application hangs on this file when trying to recognize it's format (hang in FindStreamFormat function when dcraw's TryFunction was called).

Test project with cur-file attached. "Try load" button hangs application (Needs dcrawlib.dll file in project folder to run).

Download Attachment: 201452031512_TestDCRAWSimple.zip

Uwe

284 Posts

Posted - May 18 2014 :  08:47:46  Show Profile  Reply
DCRAW is for camera RAW images, not for cursor files.

-Uwe
Go to Top of Page

goobit

11 Posts

Posted - May 18 2014 :  10:11:58  Show Profile  Reply
I didn't try to load .cur file with dcraw. It can be any similar binary data that hangs TryFunction() in dcrawlib.dll.
Go to Top of Page

Uwe

284 Posts

Posted - May 18 2014 :  10:58:18  Show Profile  Reply
Can you show us some code? Somewhere in your TryFunction you seem to feed non camera RAW data to DCRAW, and that's not possible.

-Uwe
Go to Top of Page

goobit

11 Posts

Posted - May 18 2014 :  12:24:55  Show Profile  Reply
I attach test project in first post. Now I know how to add urls for zip-files thus I reattach it in this post.

Yes, it is exactly what I do: "feed non camera RAW data to DCRAW". But in this case I expect exception or ioUnknown result.

About code: this is a part of ImageEnIO.FindStreamFormat() function for user registered file formats:

for q := 0 to iegFileFormats.Count - 1 do
  with TIEFileFormatInfo(iegFileFormats[q]) do
    if assigned(TryFunction) then
    begin
      Stream.Position := lp;
      if TryFunction(Stream,FileType) then
      begin
        result := FileType;
        break;
      end;
    end;

Code hangs in dcraw plugin TryFunction() which begins to change stream position and reread it in endless loop.

I attach "colorpicker.cur" that cause such problem. You can try to call FindStreamFormat() for it with dcraw loaded to reproduce this problem.

Test project: 20145185648_TestDCRAW.zip

colorpicker.cur: 2014518121914_colorpicker.zip
Go to Top of Page

Uwe

284 Posts

Posted - May 18 2014 :  13:08:38  Show Profile  Reply
Just a quick question: why don't you use

{...}
IEFileFormatRemove(ioRAW); // disable internal RAW support
IEAddExtIOPlugIn('dcrawlib.dll');
IEAddExtIOPlugIn('imagemagick.dll');
{...}

in the main form's OnCreate event and/ or check the file with GetAllSupportedFileExtensions or FindFileFormat (see help for details)?

-Uwe
Go to Top of Page

goobit

11 Posts

Posted - May 19 2014 :  04:11:02  Show Profile  Reply
1. This is done in dcraw loading function:

function ieLoadDcrawPlugin: Boolean;
var
  DllPath: string;
begin
  DllPath := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0))) + DcrawDllName;
  Result := IEIsExtIOPluginLoaded(DllPath);
  if not Result and FileExists(DllPath) then begin
    IEFileFormatRemove(ioRAW);
    Result := (IEAddExtIOPlugIn(DllPath) <> 0);
  end;
end;

2. As I noted earlier our application doesn't simply convert file extension (when exists) to TIOFileType. It use file extension for first try only as a hint but when this first try not successful it tries to find corresponding file format by stream binary content (iterates "try functions" for all known formats). Such algorithm will load files with invalid file extension in correct TIOFileType format.
Go to Top of Page

Uwe

284 Posts

Posted - May 19 2014 :  08:11:41  Show Profile  Reply
The FindFileFormat function uses FindStreamFormat to recognize the file type from the file header. Isn't that what you want? It even has a VerifyExtension property to determine the file type from the file extension as well.

By the way: if I try to load your CUR file with one of the demo programs (see Demos -> FullApps -> PhotoEN), the ImageEnView stays empty. But that has nothing to do with DCRAW.


-Uwe
Go to Top of Page

goobit

11 Posts

Posted - May 19 2014 :  08:57:42  Show Profile  Reply
Actually our ieFindStreamFormat() is a combination of FindStreamFormat and FindFileFormat plus some useful for us features (working with stream, "Aborted" parameter, using optionally file extension as first try suggestion that can greatly speeds up format detection).

Is PhotoEN uses dcraw? And even if it is the "colorpicker.cur" will be loaded "normally" since TImageEnIO.LoadFromFile() uses only file extension to determine image format and never tries to call FindStreamFormat(). And it wrongly determine it as ioCUR (actually it is normal windows cursor file but ImageEn can't load it in such format). You can rename this file to "colorpicker.dat" and load it with PhotoEN: empty MDI window will be created with TMDIChild.ImageEnView1.IO.Aborting = True).

PS. I use old 4.1.0 ImageEn version. But posted issue doesn't relate to ImageEn, it is dcraw plugin problem only.
Go to Top of Page

Uwe

284 Posts

Posted - May 19 2014 :  09:36:09  Show Profile  Reply
D2010 Pro:
I get a "Return value of function 'TryFunctions' might be undefined" warning when compiling.

Wouldn't TryFunctions() fail if you try to reset the stream position to 0 for a file that can't be loaded in the first place? Just a thought.

-Uwe
Go to Top of Page

goobit

11 Posts

Posted - May 20 2014 :  03:18:19  Show Profile  Reply
I remake the test project. Now it uses ImageEn code only. Needs to copy the dcrawlib.dll in project folder to work. Same result.

Test project (simple): 201452031512_TestDCRAWSimple.zip
Go to Top of Page

Uwe

284 Posts

Posted - May 21 2014 :  15:48:55  Show Profile  Reply
Sorry, I'm out of ideas. Looking at imageenio.pas, it seems that the FindStreamFormat call fails when checking for a format like CUR. Why that behavior is triggered by dcrawlib.dll, is beyond me.

-Uwe
Go to Top of Page

xequte

38615 Posts

Posted - May 22 2014 :  18:52:34  Show Profile  Reply
We are investigating...

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

Uwe

284 Posts

Posted - May 24 2014 :  15:11:00  Show Profile  Reply
Nigel,

Something's wrong with the file that the OP provided. Try any other regular CUR file and you will see that ImageEn loads it without any problem. I just checked a whole bunch of them.

-Uwe
Go to Top of Page

xequte

38615 Posts

Posted - May 24 2014 :  22:57:47  Show Profile  Reply
Thanks Uwe,

It might be a corrupt file, we have not had time to investigate yet.




Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

goobit

11 Posts

Posted - May 24 2014 :  23:22:25  Show Profile  Reply
Guys, this is correct cursor file that I found in Steam application folder while test batch loading process. At least old Imagine plugin for Total Commander open and display it normally.

I think the problem is in some binary data sequence stored in this particular file that cause infinite loop in dcraw plugin and this sequence can be found in other (non cursor) files.
Go to Top of Page

Uwe

284 Posts

Posted - May 25 2014 :  11:07:55  Show Profile  Reply
FWIW:
Just tested with IrfanView and got a warning that "colorpicker.cur" is actually an ANI file with an incorrect extension. Since this file can practically kill any application that uses ImageEn (I checked Faststone Image Viewer for example, and it crashed), I think some error handling in imageenio.pas for this type of scenario would be helpful.

-Uwe

Go to Top of Page

goobit

11 Posts

Posted - Aug 18 2014 :  01:43:52  Show Profile  Reply
I wrote to the author of DCRaw tool David Coffin and he has fixed this bug:

The bug is in the RIFF file:

000000  52 49 46 46 4A 03 00 00 41 43 4F 4E 61 6E 69 68   RIFFJ...ACONanih
                    ^^ ^^ ^^ ^^
000010  24 00 00 00 24 00 00 00 01 00 00 00 01 00 00 00   $...$...........
        ^^ ^^ ^^ ^^
000020  00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00   ................

000030  0A 00 00 00 01 00 00 00 4C 49 53 54 0A 03 00 00   ........LIST....
                                            ^^ ^^ ^^ ^^
000040  66 72 61 6D 69 63 6F 6E FE 02 00 00 00 00 02 00   framicon........
...                             ^^ ^^ ^^ ^^
000340  FF FF FF FF FF FF FF FF FF FF                     ..........


The first eight bytes mean "a RIFF of size 0x34A".
The size field is the number of bytes *after* the first
eight, but in this case 0x34A (842 decimal) is the size
of the whole file. It should be "42 03 00 00".

The size fields of the "anih", "LIST", and "icon"
tags are correct, leading dcraw to believe that the RIFF
contains eight bytes of something extra. Trying to read
this nonexistent tag causes a hang.

--- dcraw.c     2014/07/03 21:19:24     1.467
+++ dcraw.c     2014/08/17 17:33:04
@@ -6558,7 +6558,7 @@
   end = ftell(ifp) + size;
   if (!memcmp(tag,"RIFF",4) || !memcmp(tag,"LIST",4)) {
     get4();
-    while (ftell(ifp)+7 < end)
+    while (ftell(ifp)+7 < end && !feof(ifp))
       parse_riff();
   } else if (!memcmp(tag,"nctg",4)) {
     while (ftell(ifp)+7 < end) {

Go to Top of Page

xequte

38615 Posts

Posted - Aug 18 2014 :  02:38:53  Show Profile  Reply
Thanks for the update,

We'll have this in the next DCRAW release.

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

goobit

11 Posts

Posted - Feb 02 2015 :  04:35:13  Show Profile  Reply
I would like to inform that new version of dcraw was released:
Revision: 1.468
Date: 2015/01/30

Thanks!
Go to Top of Page

xequte

38615 Posts

Posted - Feb 02 2015 :  16:48:10  Show Profile  Reply
OK, thanks, we will update before too long.


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Reply to Topic
Jump To: