Skip to content

Commit 4ba9520

Browse files
committed
test(iso-integrity): Verify GPT header in UEFI ISOs
Adds a new verification step to the `test_iso_integrity_and_boot_modes` integration test. This step inspects the raw ISO image bytes to confirm the presence and correctness of the GPT (GUID Partition Table) header. It specifically asserts the "EFI PART" signature and the 1.0 revision (0x00010000) of the GPT header. This improves the robustness of UEFI ISO integrity checks, ensuring generated images correctly implement the GPT structure required for UEFI boot compatibility.
1 parent f217b84 commit 4ba9520

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

tests/integration_tests/integrity_and_boot.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::{
55
};
66

77
use isobemak::build_iso;
8-
use isobemak::{BiosBootInfo, BootInfo, IsoImage, IsoImageFile, UefiBootInfo};
98
use tempfile::tempdir;
109

1110
use crate::integration_tests::common::run_command;
@@ -119,5 +118,50 @@ fn test_iso_integrity_and_boot_modes() -> io::Result<()> {
119118
// The `test_create_isohybrid_uefi_iso` already performs detailed UEFI boot entry verification.
120119
// Removed assertion for "EFI boot entry is present" as isoinfo -d does not output this string directly.
121120

121+
// 4. Enhanced Binary Dump Inspection: Check GPT Header
122+
// Read the ISO file content
123+
let mut iso_file = File::open(&iso_path)?;
124+
let mut iso_bytes = Vec::new();
125+
iso_file.read_to_end(&mut iso_bytes)?;
126+
127+
// GPT Header is typically at LBA 1 (sector 1), which is 512 bytes from the start of the file.
128+
// A sector is 512 bytes.
129+
let gpt_header_offset = 512;
130+
let gpt_header_size = 92; // Minimum GPT header size
131+
132+
if iso_bytes.len() > gpt_header_offset + gpt_header_size {
133+
let gpt_header_slice = &iso_bytes[gpt_header_offset..(gpt_header_offset + gpt_header_size)];
134+
135+
// Check GPT Signature ("EFI PART")
136+
let signature = &gpt_header_slice[0..8];
137+
assert_eq!(signature, b"EFI PART", "GPT header signature mismatch");
138+
println!("Verified GPT header signature: {:?}", String::from_utf8_lossy(signature));
139+
140+
// Check GPT Revision (should be 0x00010000 for version 1.0)
141+
let revision = u32::from_le_bytes([
142+
gpt_header_slice[8],
143+
gpt_header_slice[9],
144+
gpt_header_slice[10],
145+
gpt_header_slice[11],
146+
]);
147+
assert_eq!(revision, 0x00010000, "GPT header revision mismatch");
148+
println!("Verified GPT header revision: 0x{:x}", revision);
149+
150+
// Further checks could include:
151+
// - Header Size (offset 12, u32)
152+
// - CRC32 of header (offset 16, u32)
153+
// - Current LBA (offset 24, u64)
154+
// - Backup LBA (offset 32, u64)
155+
// - First Usable LBA (offset 40, u64)
156+
// - Last Usable LBA (offset 48, u64)
157+
// - Disk GUID (offset 56, 16 bytes)
158+
// - Partition Entry LBA (offset 72, u64)
159+
// - Number of Partition Entries (offset 80, u32)
160+
// - Size of Partition Entry (offset 84, u32)
161+
// - CRC32 of Partition Entry Array (offset 88, u32)
162+
} else {
163+
println!("Warning: ISO file too small to contain a GPT header at expected offset.");
164+
}
165+
122166
Ok(())
123167
}

0 commit comments

Comments
 (0)