Skip to content

Develop#35

Merged
p14c31355 merged 13 commits intomainfrom
develop
Oct 5, 2025
Merged

Develop#35
p14c31355 merged 13 commits intomainfrom
develop

Conversation

@p14c31355
Copy link
Copy Markdown
Owner

Change details

  • New feature
  • Refactoring
  • Bug fix
  • CI / Build settings correction
  • Documentation update

Build / Test Results

$ cargo check     #
$ cargo test      #

p14c31355 and others added 3 commits October 5, 2025 08:55
Separates the calculation of the FAT image's logical size from its total file size.
The `logical_size` now represents the actual content and overhead, rounded up to the nearest sector, and is ensured to be at least one sector. This is the size reported back by the function in sectors.

The `total_size` is explicitly the final image file size, which ensures it meets the minimum requirements for FAT16 formatting (16MB). The FAT type determination is based on this `total_size`.

This change improves clarity by distinguishing between the actual data capacity and the physical file size required by the FAT format.
This commit introduces a new integration test, `test_iso_integrity_and_boot_modes`,
to enhance the robustness of ISO generation.

The test performs the following verifications:
- Builds an ISO with both BIOS (El Torito) and UEFI boot components.
- Verifies the ISO's integrity using `md5sum`.
- Confirms the presence and correct configuration of the El Torito boot entry
  using `isoinfo -d`.
- Extracts the BIOS boot image from the generated ISO and asserts the
  presence of the `0xAA55` boot signature, ensuring proper BIOS boot sector
  creation.

This helps ensure that the generated ISOs are valid and correctly configured
for multiple boot environments.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @p14c31355, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the internal logic for calculating FAT image sizes, ensuring more accurate representation of the logical content size within generated ISOs. Additionally, it significantly enhances the project's test suite by introducing a robust integration test that validates the integrity and bootability of ISO images across both BIOS and UEFI environments, thereby improving the overall reliability of the ISO generation process.

Highlights

  • FAT Image Size Calculation Refinement: The logic for determining FAT image size has been updated to distinguish between the logical size (content + overhead) and the total allocated size (which includes a minimum for FAT16 compatibility). The function now correctly reports the logical size in ISO sectors.
  • Comprehensive ISO Integrity Test: A new integration test, "test_iso_integrity_and_boot_modes", has been added. This test verifies the integrity of generated ISOs and ensures proper configuration for both BIOS (El Torito) and UEFI boot modes using external tools like md5sum, isoinfo, and 7z.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the FAT image size calculation and adds a new integration test for ISO integrity and boot modes. The refactoring in fat.rs correctly separates the logical image size from the total file size. However, it introduces a redundant check that can be removed. The new integration test in tests/integration.rs is a great addition for ensuring robustness, but it contains a critical logic error that will cause it to always fail, and it also misses an opportunity to handle command failures robustly. My review includes suggestions to fix these issues in the test to make it reliable and to clean up the code in fat.rs.

Comment on lines +53 to +55
if logical_size == 0 {
logical_size = SECTOR_SIZE;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This check for logical_size == 0 is unreachable. content_size is derived from file metadata lengths and will be non-negative. Since FAT_OVERHEAD is a positive constant, the sum content_size + FAT_OVERHEAD will always be greater than zero. Consequently, logical_size, which is calculated by rounding this sum up to the nearest sector size, can never be zero. This block of code can be safely removed to simplify the logic.

p14c31355 and others added 7 commits October 5, 2025 09:14
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
`fat::create_fat_image` now returns the logical size of the created FAT image in 512-byte sectors. `iso::builder::build_iso` uses this logical size to calculate the ESP size in ISO (2048-byte) sectors for the ISO builder's internal tracking.

When creating the UEFI boot catalog entry, `iso::builder_utils::create_uefi_esp_boot_entry` now correctly converts the ESP size from ISO sectors back to 512-byte sectors, as required by the boot catalog specification.

This ensures consistent and accurate handling of the EFI System Partition (ESP) size throughout the ISO creation process, resolving discrepancies between 512-byte and 2048-byte sector units and ensuring the boot catalog correctly reflects the ESP's logical size. The `build_iso` function now also returns the logical FAT image size in 512-byte sectors.
@p14c31355
Copy link
Copy Markdown
Owner Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant refactoring that improves the ISO building logic and test structure. Key changes include clarifying FAT image size calculations, making the IsoBuilder more flexible by accepting a File handle, and reorganizing integration tests into focused modules. These changes enhance maintainability and appear to fix an underlying issue with how ESP size is calculated. My review focuses on a critical overflow vulnerability and a minor code cleanup suggestion.

&mut self,
iso_path: &Path,
iso_file: &mut File, // Accept File handle directly
_iso_path: &Path, // Renamed to _iso_path to silence unused variable warning
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The _iso_path parameter is unused within the build function and is marked as such. To simplify the function's interface and remove dead code, consider removing this parameter. The path is already available in the calling build_iso function where it's needed.

p14c31355 and others added 2 commits October 5, 2025 20:23
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.
@p14c31355
Copy link
Copy Markdown
Owner Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant refactoring to the ISO building process, primarily focusing on correcting the calculation of FAT image sizes and improving the flexibility of the IsoBuilder. The changes correctly distinguish between the logical and physical size of the FAT image, fixการคำนวณขนาดพาร์ติชัน UEFI ESP ใน boot catalog, และจัดระเบียบการทดสอบ integration ใหม่ให้เป็นโมดูลที่แยกจากกัน ซึ่งเป็นการปรับปรุงที่ยอดเยี่ยม

การตรวจสอบของฉันพบปัญหาเล็กน้อยบางประการ: พารามิเตอร์ที่ไม่ได้ใช้งานในฟังก์ชัน build, ตรรกะการตรวจสอบที่ไม่ถูกต้องซึ่งอาจนำไปสู่ overflow, และการยืนยันที่ไม่ถูกต้องในการทดสอบซึ่งไม่พิจารณาการปัดเศษขนาด โดยรวมแล้ว การเปลี่ยนแปลงเหล่านี้เป็นการปรับปรุงที่แข็งแกร่งสำหรับ codebase

&mut self,
iso_path: &Path,
iso_file: &mut File, // Accept File handle directly
_iso_path: &Path, // Renamed to _iso_path to silence unused variable warning
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

ลายเซ็นฟังก์ชัน build ได้รับการปรับปรุงให้ยอมรับ &mut File ซึ่งเป็นการปรับปรุงที่ดี อย่างไรก็ตาม พารามิเตอร์ _iso_path ไม่ได้ถูกใช้งานแล้วและควรถูกลบออกเพื่อทำให้ลายเซ็นฟังก์ชันสะอาดขึ้น การเปลี่ยนแปลงนี้จะต้องถูกส่งต่อไปยังตำแหน่งที่เรียกใช้ใน build_iso ด้วย

Suggested change
&mut self,
iso_path: &Path,
iso_file: &mut File, // Accept File handle directly
_iso_path: &Path, // Renamed to _iso_path to silence unused variable warning
iso_file: &mut File, // Accept File handle directly
esp_lba: Option<u32>,

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@p14c31355
Copy link
Copy Markdown
Owner Author

/gemini summary

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request significantly refines the core logic for generating ISO images, focusing on more accurate FAT image size calculations and a cleaner IsoBuilder interface that directly handles file I/O. Alongside these functional improvements, the project's integration test suite has undergone a major overhaul, introducing a modular structure and comprehensive tests to validate ISO integrity and bootability across different environments, addressing previous testing inaccuracies and enhancing overall reliability.

Highlights

  • FAT Image Size Calculation Logic Refinement: The logic in src/fat.rs for determining FAT image sizes has been updated to clearly differentiate between the logical size (content plus overhead) and the total allocated size, ensuring proper sector alignment and meeting minimum FAT16 compatibility requirements. The create_fat_image function now returns the logical size in 512-byte sectors.
  • IsoBuilder Refactoring for Direct File Handling: The IsoBuilder struct in src/iso/builder.rs has been refactored to no longer store an Option<File>. Instead, its build method now directly accepts a mutable reference to a File, streamlining file I/O operations and simplifying the builder's internal state management.
  • Corrected UEFI Boot Catalog Sector Calculation: A fix has been implemented in src/iso/builder_utils.rs to correctly calculate the boot_image_sectors for UEFI EFI System Partitions (ESP) within the boot catalog. This ensures the value accurately reflects the size in 512-byte sectors by converting from ISO sector counts.
  • Modularization and Enhancement of Integration Tests: The project's integration tests have been significantly reorganized into a modular structure under tests/integration_tests/. This includes new dedicated modules for basic ISO creation, common utilities, integrity and boot mode verification, and isohybrid UEFI testing, addressing previous test inaccuracies and improving overall test suite robustness.
Changelog
  • src/fat.rs
    • Refined FAT image size calculation to distinguish between logical size (content + overhead) and total allocated size (minimum for FAT16).
    • Ensured logical size is at least one sector.
    • Modified create_fat_image to return the logical size in 512-byte sectors.
  • src/iso/builder.rs
    • Removed iso_file: Option<File> from IsoBuilder struct and its new method.
    • Updated build method to accept a mutable File reference directly.
    • Adjusted calls to various write functions to use the direct File reference.
    • Modified build_iso function to return the File handle and the logical FAT size in 512-byte sectors.
    • Removed the iso_builder.iso_file = Some(iso_file); line.
  • src/iso/builder_utils.rs
    • Corrected the calculation of boot_image_sectors for UEFI ESP in create_uefi_esp_boot_entry to multiply by 4, converting ISO sectors to 512-byte sectors.
  • tests/integration.rs
    • Replaced the entire file content with a module declaration mod integration_tests;.
  • tests/integration_tests/basic_iso.rs
    • Added a new test file containing the test_create_disk_and_iso integration test.
  • tests/integration_tests/common.rs
    • Added a new utility file containing common functions for integration tests: run_command, setup_integration_test_files, and verify_iso_binary_structures.
  • tests/integration_tests/integrity_and_boot.rs
    • Added a new test file containing test_iso_integrity_and_boot_modes, which verifies ISO integrity and both BIOS and UEFI boot modes.
    • Includes a fix for the BIOS boot image signature (0xAA55).
  • tests/integration_tests/isohybrid_uefi.rs
    • Added a new test file containing test_create_isohybrid_uefi_iso, specifically for isohybrid UEFI ISO creation and verification.
    • Includes a fix for the UEFI boot sector calculation in the boot catalog.
  • tests/integration_tests/mod.rs
    • Added a new module file to declare the new integration test modules.
Activity
  • gemini-code-assist[bot] provided an initial summary of changes.
  • gemini-code-assist[bot] provided a critical review comment regarding a failing test due to an incorrect BIOS boot image signature, with a suggestion.
  • gemini-code-assist[bot] provided a high-priority review comment about unchecked 7z command exit status in tests, with a suggestion to use run_command.
  • gemini-code-assist[bot] provided a medium-priority review comment about unreachable code in src/fat.rs related to logical_size == 0.
  • gemini-code-assist[bot] provided a medium-priority review comment about the unused _iso_path parameter in IsoBuilder::build.
  • p14c31355 requested a review.
  • p14c31355 requested another review.
  • gemini-code-assist[bot] provided a medium-priority review comment in Thai about the _iso_path parameter in IsoBuilder::build being unused and suggesting its removal, also mentioning the build_iso function.
  • gemini-code-assist[bot] provided a medium-priority review comment in Thai about an incorrect UEFI boot sector calculation in tests, with a suggestion for the correct calculation.
  • p14c31355 requested a summary.

@p14c31355 p14c31355 merged commit 961ca44 into main Oct 5, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant