summaryrefslogtreecommitdiff
path: root/ojluni/src/main/native/zip_util.c
diff options
context:
space:
mode:
authorAlmaz Mingaleev <mingaleev@google.com>2024-07-10 13:38:35 +0100
committerJulian Veit <claymore1298@gmail.com>2025-06-10 20:18:03 +0200
commit3134951af737ede5b1a5f32b62dddd2dcb3f1c49 (patch)
treead4d9ecd56a978eab7033006ed2d19b54cafb1d0 /ojluni/src/main/native/zip_util.c
parent7806e83ef2cb66cccc1179ea6541aa6630d52874 (diff)
Do not accept zip files with invalid headers.HEADs12.1
According to Section 4.3.6 in [1] non-empty zip file starts with local file header. 4.3.1 allows empty files, and in such case file starts with "end of central directory record". This aligns ZipFile with libziparchive modulo empty zip files - libziparchive rejects them. Tests are skipped because sc-dev branch uses ART module prebuilts, but builds tests from sources which leads to presubmit failures. Ignore-AOSP-First: b/309938635#comment1 [1] https://pkwaredownloads.blob.core.windows.net/pem/APPNOTE.txt Bug: 309938635 Test: CtsLibcoreTestCases Test: CtsLibcoreOjTestCases (cherry picked from commit 288a44a1817707110cdf5a3a6ef8377c6e10cce2) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:de4023dd7bed3c61a74397261b09d40dcd39668e) Merged-In: I545cdd49ec3cc138331145f4716c8148662a478b Change-Id: I545cdd49ec3cc138331145f4716c8148662a478b
Diffstat (limited to 'ojluni/src/main/native/zip_util.c')
-rw-r--r--ojluni/src/main/native/zip_util.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/ojluni/src/main/native/zip_util.c b/ojluni/src/main/native/zip_util.c
index aa9c5cede9..16951a78ed 100644
--- a/ojluni/src/main/native/zip_util.c
+++ b/ojluni/src/main/native/zip_util.c
@@ -878,6 +878,17 @@ ZIP_Put_In_Cache0(const char *name, ZFILE zfd, char **pmsg, jlong lastModified,
zip->locsig = JNI_TRUE;
else
zip->locsig = JNI_FALSE;
+
+ // BEGIN Android-changed: do not accept files with invalid header.
+ if (GETSIG(errbuf) != LOCSIG && GETSIG(errbuf) != ENDSIG) {
+ if (pmsg) {
+ *pmsg = strdup("Entry at offset zero has invalid LFH signature.");
+ }
+ ZFILE_Close(zfd);
+ freeZip(zip);
+ return NULL;
+ }
+ // END Android-changed: do not accept files with invalid header.
}
// This lseek is safe because it happens during construction of the ZipFile