Author Topic: cr2hdr DELETING original photos!?  (Read 2127 times)

sinuspi

  • New to the forum
  • *
  • Posts: 20
cr2hdr DELETING original photos!?
« on: February 18, 2017, 04:41:32 PM »
I did a fresh installation of CR2HDR BETA 3 today, only to find it DELETES original DNG files after converting. What the hell!? Sure, it adds a -dualiso suffix, but only after overwriting the original file! And there's no option to disable that behaviour in the settings. Not to mention it also fails to copy the original's EXIF data to the dual-ISO file, so now I'm left with a bunch of nicely converted, but de-EXIF-ed files, thanks a lot. :/

Walter Schulz

  • Hero Member
  • *****
  • Posts: 6273
Re: cr2hdr DELETING original photos!?
« Reply #1 on: February 18, 2017, 04:46:02 PM »
Already answered before you wrote that one ....

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3217
  • 60Da / 1100D / EOSM
Re: cr2hdr DELETING original photos!?
« Reply #2 on: February 18, 2017, 05:44:31 PM »
This is mainly an issue on Windows because it's file system is case-insensitive (though it could be an issue on other systems that are using a case-insenstive filesystem e.g. on the SD card). cr2hdr uses the input filename with the last three letters replaced with "DNG" (uppercase) for the output filename:
Code: [Select]
        snprintf(out_filename, sizeof(out_filename), "%s", filename);
        out_filename[len-3] = 'D';
        out_filename[len-2] = 'N';
        out_filename[len-1] = 'G';

On Windows, this means that if you give it a file that ends with .dng, it will replace that filename to end with .DNG and assume that its either a different file, or you are simply asking it to re-convert an existing converted file. On Windows, this will actually be the same file. You can use the --skip-existing command line option to prevent overwriting, but then it simply won't convert your file.

Also, if you give cr2hdr a filename with less than 3 characters, this code results in a buffer underflow, which didn't actually cause a crash or anything on my system when I tried it, but you end up with an output file called simply "NG" or just "G". It also screws up if you give it unicode characters, for example I tried a file called "test.:)" (0x1F642) and it said the output file was: "test.?DNG", but it just overwrote the original.

There's also this comment in the code:
Code: [Select]
            /* note: we only save uppercase .DNGs, so a case-sensitive extension check should be fine */
which is also not a very safe assumption to make.

Bottom line: this file handling code probably needs to be cleaned up. This would probably be considered an easy coding task, great for someone interested in getting started with contributing to ML.

sinuspi

  • New to the forum
  • *
  • Posts: 20
Re: cr2hdr DELETING original photos!?
« Reply #3 on: February 18, 2017, 10:59:26 PM »
Oh my... Directly replacing the last 3 letters with "DNG" is probably one of the most horribly unsafe piece of code I've seen... O_O

Fsck it, I'm game. Where's the source code and how can I contribute?

@Walter Schulz: Huh, indeed I thought I mentioned this already, but wasn't sure if I did or only intended to. I need to replace some memory chips in my head, I guess. :P

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3217
  • 60Da / 1100D / EOSM
Re: cr2hdr DELETING original photos!?
« Reply #4 on: February 19, 2017, 04:21:56 AM »

sinuspi

  • New to the forum
  • *
  • Posts: 20
Re: cr2hdr DELETING original photos!?
« Reply #5 on: February 20, 2017, 09:10:46 PM »
Since I have zero experience with BitBucket specifically, I wonder why it lets me edit and "commit" the file..? I thought I'd have to fork the project and then submit a pull request, and yet there's the "Commit" button, beckoning... What's with that?

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3217
  • 60Da / 1100D / EOSM
Re: cr2hdr DELETING original photos!?
« Reply #6 on: February 21, 2017, 04:01:58 PM »
It lets you basically do a pull request entirely from a browser.

Audionut

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3536
  • Blunt and to the point

sinuspi

  • New to the forum
  • *
  • Posts: 20
Re: cr2hdr DELETING original photos!?
« Reply #8 on: February 23, 2017, 12:26:55 AM »
Right, I know how to fork and request pulls, but I was baffled by the apparent ability to edit and commit to the main repo, NOT my own fork.

sinuspi

  • New to the forum
  • *
  • Posts: 20
Re: cr2hdr DELETING original photos!?
« Reply #9 on: February 23, 2017, 12:55:13 AM »
OK, here goes nothing. I committed a pull request trying to add an "--append-suffix" option to cr2hdr, making it write to "filename-DualISO.DNG", avoiding overwriting "filename.DNG". It's dry code, as I couldn't afford the time to set up a proper build env, so it may crash and burn... <_<