From 007891e97ce2f2bbf4e182ecb56b8d7328096248 Mon Sep 17 00:00:00 2001 From: lcdr Date: Wed, 26 May 2021 20:54:10 +0200 Subject: [PATCH] Fix copyStream bug for copies smaller than the buffer size --- .../src/com/jpexs/helpers/Helper.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java index 46fd40483..07a327bc6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.helpers; import com.jpexs.decompiler.flash.AppResources; @@ -730,15 +731,18 @@ public class Helper { try { final int bufSize = 4096; byte[] buf = new byte[bufSize]; + int chunkSize = bufSize; int cnt = 0; - while ((cnt = is.read(buf)) > 0) { + while (maxLength > 0) { + if (maxLength < bufSize) { + chunkSize = (int) maxLength; + } + cnt = is.read(buf, 0, chunkSize); + if (cnt <= 0) { + break; + } os.write(buf, 0, cnt); maxLength -= cnt; - - // last chunk is smaller - if (maxLength < bufSize) { - buf = new byte[(int) maxLength]; - } } } catch (IOException ex) { // ignore