From 1257f1505cb2ac75b6959e16d195c7c4bac8ee06 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Wed, 14 Jul 2021 13:58:55 +0900 Subject: [PATCH] ZipUtils: use FileChannel#size RandomAccessFile#length returns 0 for block devices while FileChannel#size returns the correct size. ZipUtils should work with block-device zip files when Android is running as a guest OS and APK/APEX files are passed via block devices. Bug: 193592496 Bug: 192366904 Test: FrameworksServicesTests Change-Id: I6472e2a9051b92a5a778b4990b8e681492985d1a --- core/java/android/util/apk/ZipUtils.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/java/android/util/apk/ZipUtils.java b/core/java/android/util/apk/ZipUtils.java index fa5477e4190bc..3ca3fc0f6338d 100644 --- a/core/java/android/util/apk/ZipUtils.java +++ b/core/java/android/util/apk/ZipUtils.java @@ -63,7 +63,8 @@ abstract class ZipUtils { // exactly the remaining bytes in the buffer. The search is bounded because the maximum // size of the comment field is 65535 bytes because the field is an unsigned 16-bit number. - long fileSize = zip.length(); + // TODO(b/193592496) RandomAccessFile#length + long fileSize = zip.getChannel().size(); if (fileSize < ZIP_EOCD_REC_MIN_SIZE) { return null; } @@ -110,7 +111,8 @@ abstract class ZipUtils { throw new IllegalArgumentException("maxCommentSize: " + maxCommentSize); } - long fileSize = zip.length(); + // TODO(b/193592496) RandomAccessFile#length + long fileSize = zip.getChannel().size(); if (fileSize < ZIP_EOCD_REC_MIN_SIZE) { // No space for EoCD record in the file. return null;