From ed3b54e4eb3cea21099023f685b0908a09e616d0 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Tue, 23 Oct 2018 15:43:24 +0200 Subject: [PATCH] DNG files from DJI FC6310 open extremely slow, fixes #4888 --- rtengine/dcraw.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc index 73f9c948f..f1e2b73bb 100644 --- a/rtengine/dcraw.cc +++ b/rtengine/dcraw.cc @@ -6462,17 +6462,20 @@ guess_cfa_pc: unsigned oldOrder = order; order = 0x4d4d; // always big endian per definition in https://www.adobe.com/content/dam/acom/en/products/photoshop/pdfs/dng_spec_1.4.0.0.pdf chapter 7 unsigned ntags = get4(); // read the number of opcodes - while (ntags--) { - unsigned opcode = get4(); - fseek (ifp, 8, SEEK_CUR); // skip 8 bytes as they don't interest us currently - if (opcode == 4) { // FixBadPixelsConstant - fseek (ifp, 4, SEEK_CUR); // skip 4 bytes as we know that the opcode 4 takes 4 byte - if(get4() == 0) { // if raw 0 values should be treated as bad pixels, set zero_is_bad to true (1). That's the only value currently supported by rt - zero_is_bad = 1; + + if (ntags < ifp->size / 12) { // rough check for wrong value (happens for example with DNG files from DJI FC6310) + while (ntags-- && !ifp->eof) { + unsigned opcode = get4(); + fseek (ifp, 8, SEEK_CUR); // skip 8 bytes as they don't interest us currently + if (opcode == 4) { // FixBadPixelsConstant + fseek (ifp, 4, SEEK_CUR); // skip 4 bytes as we know that the opcode 4 takes 4 byte + if(get4() == 0) { // if raw 0 values should be treated as bad pixels, set zero_is_bad to true (1). That's the only value currently supported by rt + zero_is_bad = 1; + } + } else { + fseek (ifp, get4(), SEEK_CUR); + } } - } else { - fseek (ifp, get4(), SEEK_CUR); - } } order = oldOrder; break;