https://github.com/LibRaw/LibRaw/commit/82616eff4c7f7437e96bdeeed238c3ef3dc12d60 Index: rawtherapee-5.2/rtengine/dcraw.c =================================================================== --- rawtherapee-5.2/rtengine/dcraw.c +++ rawtherapee-5.2/rtengine/dcraw.c 2017-09-28 11:18:57.663860478 -0400 @@ -4647,6 +4647,10 @@ void CLASS xtrans_interpolate (int passes) { int c, d, f, g, h, i, v, ng, row, col, top, left, mrow, mcol; +#ifdef LIBRAW_LIBRARY_BUILD + int cstat[4]={0,0,0,0}; +#endif + int val, ndir, pass, hm[8], avg[4], color[3][8]; static const short orth[12] = { 1,0,0,1,-1,0,0,-1,1,0,0,1 }, patt[2][16] = { { 0,1,0,-1,2,0,-1,0,1,1,1,-1,0,0,0,0 }, @@ -4662,6 +4666,18 @@ if (verbose) fprintf (stderr,_("%d-pass X-Trans interpolation...\n"), passes); +#ifdef LIBRAW_LIBRARY_BUILD +/* Check against right pattern */ + for (row = 0; row < 6; row++) + for (col = 0; col < 6; col++) + cstat[fcol(row,col)]++; + + if(cstat[0] < 6 || cstat[0]>10 || cstat[1]< 16 + || cstat[1]>24 || cstat[2]< 6 || cstat[2]>10 || cstat[3]) + throw LIBRAW_EXCEPTION_IO_CORRUPT; +#endif + + cielab (0,0); ndir = 4 << (passes > 1); buffer = (char *) malloc (TS*TS*(ndir*11+6)); @@ -6732,7 +6748,11 @@ fuji_width = !(fgetc(ifp) & 8); } else if (tag == 0x131) { filters = 9; - FORC(36) xtrans_abs[0][35-c] = fgetc(ifp) & 3; + FORC(36) + { + int q = fgetc(ifp); + xtrans_abs[0][35 - c] = MAX(0,MIN(q,2)); /* & 3;*/ + } } else if (tag == 0x2ff0) { FORC4 cam_mul[c ^ 1] = get2(); } else if (tag == 0xc000) {