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

Segfault when opening compressed CR3 and cropped raw from Canon R5 #6279

Closed
2 tasks
Thanatomanic opened this issue Jun 15, 2021 · 7 comments
Closed
2 tasks
Assignees
Labels
priority: medium Will be fixed at a moderate pace scope: file format Camera or image file formats type: bug Something is not doing what it's supposed to be doing

Comments

@Thanatomanic
Copy link
Contributor

Thanatomanic commented Jun 15, 2021

See here for the original report: https://discuss.pixls.us/t/canon-r5-cropped-raws/25441

This file does not decode, but instead segfaults R5__0596.ZIP. It is shot as a lossy compressed cRAW in APS-C mode with a crop factor applied. ExifTool tells me:

Compression=JPEG (old-style)
ImageWidth=ExifImageWidth=CroppedImageWidth=SourceImageWidth=5088
ImageHeight=ExifImageHeight=CroppedImageHeight=SourceImageWidth=3392
AspectRatio=3:2 (APS-C crop)
SensorWidth=5248
SensorHeight=3510
SensorLeftBorder=144
SensorTopBorder=108
SensorRightBorder=5231
SensorBottomBorder=3499

There are two issues at play.

In any case, it shouldn't segfault.

@Thanatomanic Thanatomanic added type: bug Something is not doing what it's supposed to be doing scope: file format Camera or image file formats priority: medium Will be fixed at a moderate pace labels Jun 15, 2021
@heckflosse
Copy link
Collaborator

heckflosse commented Jun 15, 2021

Here's a quick and very dirty patch to avoid the segfault. It's not meant to be committed, but as a starting point for a better patch.

diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc
index ef0b4e8dc..e631d4828 100644
--- a/rtengine/dcraw.cc
+++ b/rtengine/dcraw.cc
@@ -4397,6 +4397,11 @@ void CLASS crop_masked_pixels()
       }
     }
   } else {
+    // dirty hack to show what's wrong and avoid segfault
+    if (height == 3510 && width == 5248 && !strncmp(model, "EOS R5", 6)) {
+        top_margin = 0;
+        left_margin = 0;
+    }
 #ifdef _OPENMP
 #pragma omp parallel for
 #endif

Maybe another dev ( @Thanatomanic ) can make a more correct patch.

Ingo

@Thanatomanic
Copy link
Contributor Author

The main issue is that our camconst.json format can only handle one particular raw crop per camera, whereas this camera (and others like it) can have multiple depending on a shooting mode. The smaller raw image sizes are read correctly by dcraw, but the crop values in camconst indicate a bigger file, so too much memory is being read leading to the segfault. The actual segfault happens in this function

void CLASS crop_masked_pixels()

I don't think we should be casually hacking that. A slightly better workaround may be similar to this #6255

To be continued...

@Thanatomanic
Copy link
Contributor Author

For reference, @agriggio has implemented raw size-dependent crops: https://bitbucket.org/agriggio/art/commits/c8df72cfd2b0c15fda1f5d5c3c5364161daff1bc

@Floessie
Copy link
Collaborator

I like how Alberto adopted my style for writing lambdas. 😎

@virxkane
Copy link

I guess same problem with CR3 raw files from Canon EOS R and 1.6 crop mode.
log.txt
current git 'dev' branch

@EGD
Copy link

EGD commented Aug 11, 2021

Same problem with Canon EOS R6 (#6330).

@heckflosse heckflosse self-assigned this Aug 11, 2021
@heckflosse
Copy link
Collaborator

I did some hacking. Here's a first result. Still needs some work.

grafik

heckflosse added a commit that referenced this issue Sep 3, 2021
pmjdebruijn pushed a commit to pmjdebruijn/RawTherapee that referenced this issue Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium Will be fixed at a moderate pace scope: file format Camera or image file formats type: bug Something is not doing what it's supposed to be doing
Projects
None yet
Development

No branches or pull requests

5 participants