Commit 9b60c005 authored by topjohnwu's avatar topjohnwu

Support multiple CPIO concatenated

parent cc6ca0bd
...@@ -210,16 +210,25 @@ bool cpio::mv(const char *from, const char *to) { ...@@ -210,16 +210,25 @@ bool cpio::mv(const char *from, const char *to) {
void cpio::load_cpio(const char *buf, size_t sz) { void cpio::load_cpio(const char *buf, size_t sz) {
size_t pos = 0; size_t pos = 0;
while (pos < sz) { while (pos < sz) {
auto header = reinterpret_cast<const cpio_newc_header *>(buf + pos); auto hdr = reinterpret_cast<const cpio_newc_header *>(buf + pos);
if (memcmp(hdr->magic, "070701", 6) != 0)
LOGE("bad cpio header\n");
pos += sizeof(cpio_newc_header); pos += sizeof(cpio_newc_header);
string_view name(buf + pos); string_view name(buf + pos);
pos += x8u(header->namesize); pos += x8u(hdr->namesize);
pos_align(pos); pos_align(pos);
if (name == "." || name == "..") if (name == "." || name == "..")
continue; continue;
if (name == "TRAILER!!!") if (name == "TRAILER!!!") {
break; // Android support multiple CPIO being concatenated
auto entry = new cpio_entry(header); // Search for the next cpio header
auto next = static_cast<const char *>(memmem(buf + pos, sz - pos, "070701", 6));
if (next == nullptr)
break;
pos = next - buf;
continue;
}
auto entry = new cpio_entry(hdr);
entry->data = xmalloc(entry->filesize); entry->data = xmalloc(entry->filesize);
memcpy(entry->data, buf + pos, entry->filesize); memcpy(entry->data, buf + pos, entry->filesize);
pos += entry->filesize; pos += entry->filesize;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment