From 565d7ef04b85f3878f51816f4af255ccbc44148a Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 6 Aug 2026 12:45:36 +0200 Subject: [PATCH] fix: Hexadecimal El Torito load size parsing (#2072) --- src/image.sh | 34 ++++++++++++++++++++++------------ src/install.sh | 2 +- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/image.sh b/src/image.sh index d4ce1f8a..04ea0483 100644 --- a/src/image.sh +++ b/src/image.sh @@ -806,7 +806,7 @@ detectLegacy() { if [ -n "$marker" ]; then error "Windows IA-64 (Itanium) images are not supported by this container!" - return 1 + exit 67 fi marker=$(find "$dir" -maxdepth 1 -type d -iname WIN95 -print -quit) || return 1 @@ -1215,7 +1215,7 @@ readImageInfo() { local wim="$1" local result="" - result=$(wimlib-imagex info -xml "$wim" | iconv -f UTF-16LE -t UTF-8) || { + result=$(wimlib-imagex info --xml "$wim" | iconv -f UTF-16LE -t UTF-8) || { local rc=$? if (( rc >= 129 )); then @@ -1858,8 +1858,7 @@ getBootLoadSize() { return 1 fi - BOOT_LOAD_SIZE=$((size / 512)) - ;; + BOOT_LOAD_SIZE=$((size / 512)) ;; * ) @@ -1876,13 +1875,16 @@ getBootLoadSize() { return 1 fi - if [[ ! "$value" =~ ^[0-9]+$ ]] || [ "${#value}" -gt 5 ]; then + if [[ "$value" =~ ^[[:digit:]]{1,5}$ ]]; then + BOOT_LOAD_SIZE=$((10#$value)) + elif [[ "$value" =~ ^(0[xX])?[[:xdigit:]]{1,4}$ ]]; then + value=${value#0x} + value=${value#0X} + BOOT_LOAD_SIZE=$((16#$value)) + else error "Invalid boot image load size found in $desc ISO!" return 1 - fi - - BOOT_LOAD_SIZE=$((10#$value)) - ;; + fi ;; esac if (( BOOT_LOAD_SIZE < 1 || BOOT_LOAD_SIZE > 65535 )); then @@ -1899,7 +1901,7 @@ extractBootImage() { local dir="$2" local desc="$3" - local offset info + local actual expected offset info ETFS="boot.img" @@ -1932,9 +1934,17 @@ extractBootImage() { return 1 fi - if [ ! -s "$dir/$ETFS" ]; then + expected=$((BOOT_LOAD_SIZE * 512)) + + if ! actual=$(stat -c%s "$dir/$ETFS"); then rm -f "$dir/$ETFS" || true - error "Failed to locate file \"$ETFS\" in $desc ISO image!" + error "Failed to determine boot image size from $desc ISO!" + return 1 + fi + + if (( actual != expected )); then + rm -f "$dir/$ETFS" || true + error "Failed to extract complete boot image from $desc ISO!" return 1 fi diff --git a/src/install.sh b/src/install.sh index 8c81d5bc..b0a0623b 100644 --- a/src/install.sh +++ b/src/install.sh @@ -1210,7 +1210,7 @@ updateImage() { # Windows Setup normally resides in boot image 2; single-image media uses 1. local idx="1" - if ! info=$(wimlib-imagex info -xml "$wim" | iconv -f UTF-16LE -t UTF-8); then + if ! info=$(wimlib-imagex info --xml "$wim" | iconv -f UTF-16LE -t UTF-8); then warn "failed to read boot image information, $FB" MANUAL="Y" info=""