This cl supports the parsing and extraction of the zip entry who has a large size than UINT32_MAX. Also add a few checks in the entry writers to make sure callers have enough space for extraction. As many users of the library assume the entry size to be 32 bits long, we keep the 32 bit ZipEntry. We also keep the functions that expect the 32 bit ZipEntry in the public header file. These 32 bit wrappers could be removed later once all users recognize the 64 bit ZipEntry. Bug: 150900468 Test: unit tests pass Change-Id: Ia6760638ccf51e97dbef6bd55dff352f1e7ce816
51 lines
1.5 KiB
C++
51 lines
1.5 KiB
C++
/*
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include "zip_error.h"
|
|
|
|
#include <android-base/macros.h>
|
|
|
|
static const char* kErrorMessages[] = {
|
|
"Success",
|
|
"Iteration ended",
|
|
"Zlib error",
|
|
"Invalid file",
|
|
"Invalid handle",
|
|
"Duplicate entries in archive",
|
|
"Empty archive",
|
|
"Entry not found",
|
|
"Invalid offset",
|
|
"Inconsistent information",
|
|
"Invalid entry name",
|
|
"I/O error",
|
|
"File mapping failed",
|
|
"Allocation failed",
|
|
"Unsupported zip entry size",
|
|
};
|
|
|
|
const char* ErrorCodeString(int32_t error_code) {
|
|
// Make sure that the number of entries in kErrorMessages and the ZipError
|
|
// enum match.
|
|
static_assert((-kLastErrorCode + 1) == arraysize(kErrorMessages),
|
|
"(-kLastErrorCode + 1) != arraysize(kErrorMessages)");
|
|
|
|
const uint32_t idx = -error_code;
|
|
if (idx < arraysize(kErrorMessages)) {
|
|
return kErrorMessages[idx];
|
|
}
|
|
|
|
return "Unknown return code";
|
|
}
|