Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Invalid write crash when opening certain RAW images #3115

Closed
AdamMainsTL opened this issue Sep 29, 2021 · 14 comments · Fixed by #4448 · May be fixed by #3125
Closed

[BUG] Invalid write crash when opening certain RAW images #3115

AdamMainsTL opened this issue Sep 29, 2021 · 14 comments · Fixed by #4448 · May be fixed by #3125
Labels
file formats Image file formats, ImageInput, ImageOutput

Comments

@AdamMainsTL
Copy link
Contributor

AdamMainsTL commented Sep 29, 2021

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
@AdamMainsTL AdamMainsTL changed the title [BUG] Invalid write crash when opening Pentax K-5IIS RAW image [BUG] Invalid write crash when opening certain RAW images Sep 29, 2021
@AdamMainsTL
Copy link
Contributor Author

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.

@lgritz
Copy link
Collaborator

lgritz commented Oct 10, 2021

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
Copy link
Collaborator

lgritz commented Oct 10, 2021

I see what's going on now.

@lgritz
Copy link
Collaborator

lgritz commented Oct 10, 2021

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?

@AdamMainsTL
Copy link
Contributor Author

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

@AdamMainsTL
Copy link
Contributor Author

AdamMainsTL commented Oct 12, 2021

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.

@lgritz
Copy link
Collaborator

lgritz commented Oct 12, 2021

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.

@AdamMainsTL
Copy link
Contributor Author

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

@lgritz
Copy link
Collaborator

lgritz commented Oct 13, 2021

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).

@AdamMainsTL
Copy link
Contributor Author

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

@Shootfast
Copy link
Contributor

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

@fabiencastan
Copy link
Contributor

What is the status of this issue?

@AdamMainsTL
Copy link
Contributor Author

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?

@Shootfast
Copy link
Contributor

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.

@lgritz lgritz added the file formats Image file formats, ImageInput, ImageOutput label Sep 27, 2023
@lgritz lgritz closed this as completed in e45a625 Sep 27, 2024
lgritz pushed a commit to lgritz/OpenImageIO that referenced this issue Sep 29, 2024
…tion#4448)

This adds a null pointer check in the raw input plugin when the user
requested raw bayer data for a file format which doesn't have it. With
this fix OIIO shows an error instead of crashing in such case.

This fixes the issue mentioned in the comments of AcademySoftwareFoundation#4361. The title issue
of AcademySoftwareFoundation#4361 has been resolved in LibRaw 0.22.0, so we can close that issue,
I guess.

This also fixes the crash on 5 out of 6 examples in AcademySoftwareFoundation#3115. The last one
is unrelated, and I don't have a good fix for that at this time (crash
due to the raw buffer having half resolution, with the pixel aspect
ratio of 0.5). Perhaps we could create a separate issue and close AcademySoftwareFoundation#3115.

I have not added any tests for this change specifically, as it is fairly
trivial.
I have started working on a more comprehensive test suite for the raw
plugin / rawtoaces, but it's not ready yet, and I'm not sure where it
should live at this stage.

Signed-off-by: Anton Dukhovnikov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
file formats Image file formats, ImageInput, ImageOutput
Projects
None yet
4 participants