From 11eec4a398f3fc1b9d39c1d3b81b53ae85d9b5e6 Mon Sep 17 00:00:00 2001 From: DRC Date: Mon, 26 Jun 2017 20:48:02 -0500 Subject: [PATCH] TJBench: Fix errors when decomp. files w/ ICC data Embedded ICC profiles can cause the size of a JPEG file to exceed the size returned by tjBufSize() (which is really meant to be used for compression anyhow, not for decompression), and this was causing a segfault (C) or an ArrayIndexOutOfBoundsException (Java) when decompressing such files with TJBench. This commit modifies the benchmark such that, when tiled decompression is disabled, it re-uses the source buffer as the primary JPEG buffer. --- java/TJBench.java | 4 ++-- tjbench.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/java/TJBench.java b/java/TJBench.java index 23fab61..618cc97 100644 --- a/java/TJBench.java +++ b/java/TJBench.java @@ -1,5 +1,5 @@ /* - * Copyright (C)2009-2014, 2016 D. R. Commander. All Rights Reserved. + * Copyright (C)2009-2014, 2016-2017 D. R. Commander. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -582,8 +582,8 @@ class TJBench { System.out.print("N/A N/A "); jpegBuf = new byte[1][TJ.bufSize(_tilew, _tileh, subsamp)]; jpegSize = new int[1]; + jpegBuf[0] = srcBuf; jpegSize[0] = srcSize; - System.arraycopy(srcBuf, 0, jpegBuf[0], 0, srcSize); } if (w == tilew) diff --git a/tjbench.c b/tjbench.c index 9db1968..626788b 100644 --- a/tjbench.c +++ b/tjbench.c @@ -1,5 +1,5 @@ /* - * Copyright (C)2009-2016 D. R. Commander. All Rights Reserved. + * Copyright (C)2009-2017 D. R. Commander. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -668,7 +668,9 @@ int decompTest(char *filename) { if(quiet==1) printf("N/A N/A "); jpegsize[0]=srcsize; - memcpy(jpegbuf[0], srcbuf, srcsize); + free(jpegbuf[0]); + jpegbuf[0]=srcbuf; + srcbuf=NULL; } if(w==tilew) _tilew=_w; -- 2.40.0