Revert "Update AVB hash header image_size to match unpacked original_image_size."

This reverts commit d9a9b02c27.
This commit is contained in:
LoveSy
2026-09-23 18:57:19 -07:00
committed by John Wu
parent 32998d6991
commit 07390a7860
2 changed files with 1 additions and 95 deletions
+1 -27
View File
@@ -906,36 +906,10 @@ void repack(Utf8CStr src_img, Utf8CStr out_img, bool skip_comp) {
memcpy(footer, boot.avb_footer, sizeof(AvbFooter));
footer->original_image_size = __builtin_bswap64(aosp_img_size);
footer->vbmeta_offset = __builtin_bswap64(off.vbmeta);
auto vbmeta = reinterpret_cast<AvbVBMetaImageHeader*>(out.data() + off.vbmeta);
if (check_env("PATCHVBMETAFLAG")) {
auto vbmeta = reinterpret_cast<AvbVBMetaImageHeader*>(out.data() + off.vbmeta);
vbmeta->flags = __builtin_bswap32(3);
}
// Sync hash descriptor image_size with the new AOSP portion size.
// Without this, some bootloaders (e.g. Motorola) reject images.
for (auto &desc : vbmeta->descriptors()) {
if (__builtin_bswap64(desc.tag) != AVB_DESCRIPTOR_TAG_HASH)
continue;
// enforce size limits; protect against adversarial input.
size_t buf_remaining = out.data() + out.size() - reinterpret_cast<uint8_t *>(&desc);
if (buf_remaining < __builtin_bswap64(desc.num_bytes_following) || buf_remaining - __builtin_bswap64(desc.num_bytes_following) < sizeof(AvbDescriptor)) {
// beware: both conditions are necessary because underflow in the subtraction could wrap
fprintf(stderr, "AVB hash descriptor num_bytes_following overflows buffer\n");
break;
}
if (__builtin_bswap64(desc.num_bytes_following) < sizeof(AvbHashDescriptor) - sizeof(AvbDescriptor)) {
fprintf(stderr, "AvbDescriptor too small to hold AvbHashDescriptor\n");
break;
}
auto &hd = reinterpret_cast<AvbHashDescriptor &>(desc);
hd.image_size = __builtin_bswap64(aosp_img_size);
break;
}
}
if (boot.flags[DHTB_FLAG]) {