diff --git a/src/install.sh b/src/install.sh index f579833..5aed2fd 100644 --- a/src/install.sh +++ b/src/install.sh @@ -447,22 +447,45 @@ extractESD() { size=9606127360 checkFreeSpace "$dir" "$size" || return 1 + local esdInfo + esdInfo=$(wimlib-imagex info "$iso") || { + error "Cannot read ESD file information!" + return 1 + } + local esdImageCount - esdImageCount=$(wimlib-imagex info "$iso" | awk '/Image Count:/ {print $3}') + esdImageCount=$(awk '/Image Count:/ {print $3}' <<< "$esdInfo") if [ -z "$esdImageCount" ]; then error "Cannot read the image count in ESD file!" && return 1 fi - sizes=$(wimlib-imagex info "$iso" | grep "Total Bytes:") - links=$(wimlib-imagex info "$iso" | grep "Hard Link Bytes:") + if (( esdImageCount < 3 )); then + error "Invalid ESD file: expected at least 3 images, found $esdImageCount." + return 1 + fi + + sizes=$(grep "Total Bytes:" <<< "$esdInfo" || true) + links=$(grep "Hard Link Bytes:" <<< "$esdInfo" || true) total1=$(awk "NR==1{ print; }" <<< "$sizes" | cut -d':' -f2 | sed 's/^ *//') links1=$(awk "NR==1{ print; }" <<< "$links" | cut -d':' -f2 | sed 's/^ *//') + + if [[ ! "$total1" =~ ^[0-9]+$ ]] || [[ ! "$links1" =~ ^[0-9]+$ ]]; then + error "Cannot read bootdisk size from ESD file!" + return 1 + fi + total=$(( total1 - links1 )) total3=$(awk "NR==3{ print; }" <<< "$sizes" | cut -d':' -f2 | sed 's/^ *//') links3=$(awk "NR==3{ print; }" <<< "$links" | cut -d':' -f2 | sed 's/^ *//') + + if [[ ! "$total3" =~ ^[0-9]+$ ]] || [[ ! "$links3" =~ ^[0-9]+$ ]]; then + error "Cannot read bootdisk size from ESD file!" + return 1 + fi + total3=$(( total3 - links3 )) total3=$(( total3 + 60000000 )) diff --git a/src/mido.sh b/src/mido.sh index 59c8400..9a2180a 100644 --- a/src/mido.sh +++ b/src/mido.sh @@ -589,22 +589,22 @@ getESD() { echo "$result" > "$dir/$eFile" - local tag="FilePath" - ESD=$(xmllint --nonet --xpath "//$tag" "$dir/$eFile" | sed -E -e "s/<[\/]?$tag>//g" 2>/dev/null) + tag="FilePath" + ESD=$(xmllint --nonet --xpath "//$tag" "$dir/$eFile" 2>/dev/null | sed -E -e "s/<[\/]?$tag>//g" || true) if [ -z "$ESD" ]; then error "Failed to find ESD URL in $eFile!" && return 1 fi tag="Sha1" - ESD_SUM=$(xmllint --nonet --xpath "//$tag" "$dir/$eFile" | sed -E -e "s/<[\/]?$tag>//g" 2>/dev/null) + ESD_SUM=$(xmllint --nonet --xpath "//$tag" "$dir/$eFile" 2>/dev/null | sed -E -e "s/<[\/]?$tag>//g" || true) if [ -z "$ESD_SUM" ]; then error "Failed to find ESD checksum in $eFile!" && return 1 fi tag="Size" - ESD_SIZE=$(xmllint --nonet --xpath "//$tag" "$dir/$eFile" | sed -E -e "s/<[\/]?$tag>//g" 2>/dev/null) + ESD_SIZE=$(xmllint --nonet --xpath "//$tag" "$dir/$eFile" 2>/dev/null | sed -E -e "s/<[\/]?$tag>//g" || true) if [ -z "$ESD_SIZE" ]; then error "Failed to find ESD filesize in $eFile!" && return 1