OpenImageIO icon indicating copy to clipboard operation
OpenImageIO copied to clipboard

[BUG] Invalid write crash when opening certain RAW images

Open AmyMaeTL opened this issue 4 years ago • 14 comments

Describe the bug When opening some RAW images I get a hard crash in my application when opening them with raw:Demosaic = "none". Specifically the debugger says:

HEAP[prog.exe]: Heap block at 000002166E310F50 modified at 000002166E312908 past requested size of 19a8

Crash stack for reference: image

To Reproduce Steps to reproduce the behavior:

  1. Download image from evidence
  2. Open image
  3. Crash

Expected behavior No crash please. Would expect it to throw an exception we can handle.

Evidence Here is a direct link to the images which should be able to reproduce the crash. Just in case I'll also zip it and attach them here.

http://www.rawsamples.ch/raws/pentax/RAW_PENTAX_K5IIS.PEF RAW_PENTAX_K5IIS.zip

http://www.rawsamples.ch/raws/nikon/d1x/RAW_NIKON_D1X.NEF RAW_NIKON_D1X.zip

http://www.rawsamples.ch/raws/canon/40d/RAW_CANON_40D_SRAW_V103.CR2 RAW_CANON_40D_SRAW_V103.zip

http://www.rawsamples.ch/raws/kodak/RAW_KODAK_C330_FORMAT422_YRGB.RAW RAW_KODAK_C330_FORMAT422_YRGB.zip

http://www.rawsamples.ch/raws/kodak/RAW_KODAK_C330_FORMAT420_YRGB.RAW RAW_KODAK_C330_FORMAT420_YRGB.zip

http://www.rawsamples.ch/raws/kodak/RAW_KODAK_C330_FORMAT_NONE_YRGB.RAW RAW_KODAK_C330_FORMAT_NONE_YRGB.zip

Platform information:

  • OIIO branch/version: 2.3.7.2
  • OS: Windows
  • C++ compiler: VS 2019
  • Any non-default build flags when you build OIIO: libraw, heic support

AmyMaeTL avatar Sep 29 '21 19:09 AmyMaeTL

Sorry, I forgot some important info which is that this happens when setting raw:Demosaic to none. Updated post/title. I believe these images work fine when we used AHD.

AmyMaeTL avatar Oct 08 '21 20:10 AmyMaeTL

Thanks, that was an important clue!

I can reproduce now. I wasn't able to without knowing about the demosaic hint. Stay tuned, looking into it.

lgritz avatar Oct 10 '21 02:10 lgritz

I see what's going on now.

lgritz avatar Oct 10 '21 03:10 lgritz

Fix proposed in #3125

Do you have the ability to apply that patch on your end and verify that it works for all the cases that crashed for you?

lgritz avatar Oct 10 '21 04:10 lgritz

I can test it out later today, will get back to you as soon as I can.

AmyMaeTL avatar Oct 12 '21 14:10 AmyMaeTL

I got this built and loaded, but it still crashes on 4/6 of the images listed above. This patch does seem to fix the NEF and PEF files though.

For the other 4 (Canon CR2 and all the Kodak files), they crash in convert_pixel_values:

image

I do have several other images that I may not be able to post to evidence for that crash, but I'll try to check if any of them crash in a unique way outside of the above stack trace.

AmyMaeTL avatar Oct 12 '21 15:10 AmyMaeTL

Oh, sorry. The very first one I tried crashed, so when I fixed it, I thought I had it nailed. That's not very thorough of me, I should have checked them all. Will try to get to this today.

lgritz avatar Oct 12 '21 20:10 lgritz

I've certainly had that feeling before. Thank you very much for working on this!

AmyMaeTL avatar Oct 12 '21 21:10 AmyMaeTL

It looks like I fixed the non-rotated case, but the rotated cases are doing the wrong thing when not demosaicing. I'm a little afraid of clobbering the in-progress of @shootfast who says he has in-progress patches about this very issue, so I'm considering just handing the problem off to him (which he may have already fixed, for all I know).

lgritz avatar Oct 13 '21 01:10 lgritz

Another update. I'm not sure if this is 100% the same bug, but it seems to be crashing in the same place. Specifically on Fuji RAW files that have a 4x4 pattern, opening with demosaic none crashes. 6x6 and 2x2 patterns seem to work fine.

Here are some files: http://www.rawsamples.ch/raws/fuji/e550/RAW_FUJI_E550.RAF http://www.rawsamples.ch/raws/fuji/e900/RAW_FUJI_E900.RAF http://www.rawsamples.ch/raws/fuji/RAW_FUJI_S9600.RAF

AmyMaeTL avatar Oct 25 '21 22:10 AmyMaeTL

Ah amazing, thanks for all the example files. I'll make sure this is fixed up soon!

Shootfast avatar Oct 26 '21 09:10 Shootfast

What is the status of this issue?

fabiencastan avatar Oct 21 '22 22:10 fabiencastan

What is the status of this issue?

I haven't heard of any sort of update to this and the files posted still crash. As far as I'm aware @Shootfast was going to handle this, but I think they are probably busy with other things.

@lgritz Do you have any idea on the status? If the original plan of the RAW patch isn't happening do you think it's worthwhile to simply handle the individual cases?

AmyMaeTL avatar Nov 01 '22 15:11 AmyMaeTL

Just bumping this for my own benefit. I'm sorry about the absolute snails pace of updates / development. I am hoping to have something very soon.

Shootfast avatar Sep 18 '23 19:09 Shootfast