Skip to content

Commit 5a11ecd

Browse files
authored
Fix integer overflow in disk size calculation for S3 storage (hestiacp#4488)
Resolved an issue with calculating available disk space when mounting a backup filesystem on S3 storage, which caused integer overflow due to values exceeding the 32-bit integer limit. This change addresses the problem of receiving a negative value (-16MB) due to integer overflow when handling large available space values from S3 storage. The use of bc ensures accurate calculations for large numbers, preventing overflow issues.
1 parent dd8f9fc commit 5a11ecd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

bin/v-backup-user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ email=$(grep CONTACT "$HESTIA/data/users/$ROOT_USER/user.conf" | cut -f 2 -d \')
178178

179179
# Validate available disk space (take usage * 2, due to the backup handling)
180180
let u_disk=$(($(get_user_disk_usage) * 2))
181-
let v_disk=$(($(stat -f --format="%a*%S" $BACKUP)))/1024/1024
181+
let v_disk=$(echo "$(stat -f --format='%a*%S' $BACKUP) / 1024 / 1024" | bc)
182182

183183
if [ "$u_disk" -gt "$v_disk" ]; then
184184
let u_disk_original=$(get_user_disk_usage)

0 commit comments

Comments
 (0)