Bug 1383081 - (DLC) DownloadAction: Flush stream before verifying checksum. r?mcomella draft
authorSebastian Kaspari <s.kaspari@gmail.com>
Fri, 21 Jul 2017 17:45:22 +0200
changeset 613132 c206348fa487414d49f0c23221dd12fd72b2cfd9
parent 613131 402d4c3e0d2923b4a87749c4db313aff767fab52
child 638629 13ebcbaea292cb2b38aa5f52770b6708676c983d
push id69745
push users.kaspari@gmail.com
push dateFri, 21 Jul 2017 18:20:23 +0000
reviewersmcomella
bugs1383081
milestone56.0a1
Bug 1383081 - (DLC) DownloadAction: Flush stream before verifying checksum. r?mcomella MozReview-Commit-ID: 9hrUM9Jv6dA
mobile/android/base/java/org/mozilla/gecko/dlc/DownloadAction.java
--- a/mobile/android/base/java/org/mozilla/gecko/dlc/DownloadAction.java
+++ b/mobile/android/base/java/org/mozilla/gecko/dlc/DownloadAction.java
@@ -232,16 +232,20 @@ public class DownloadAction extends Base
             // a reference to that stream we wouldn't be able to close it if GZInputStream throws.
             // (The BufferedInputStream constructor doesn't throw, so we don't need to care about it.)
             inputStream = new BufferedInputStream(new FileInputStream(sourceFile));
             gzInputStream = new GZIPInputStream(inputStream);
             outputStream = new BufferedOutputStream(new FileOutputStream(temporaryFile));
 
             IOUtils.copy(gzInputStream, outputStream);
 
+            // We need to flush the output stream here so that everything is written before we verify
+            // the checksum of the file.
+            outputStream.flush();
+
             if (!verify(temporaryFile, checksum)) {
                 Log.w(LOGTAG, "Checksum of extracted file does not match.");
                 return;
             }
 
             move(temporaryFile, destinationFile);
         } catch (IOException e) {
             // We could not extract to the destination: Keep temporary file and try again next time we run.