Check qcow2 before converting it to raw to prohibit DOS
@@ -40,6 +40,26 @@ IMAGE_EXTENSION=$(echo $IMAGE_PATH | sed -n -e 's/^.*\.\(.*\)$/\1/p')
mkdir -p $COPY_PATH
echo $IMAGE_NAME | grep -q -e "raw" -e "qcow2"
if [ $? -ne 0 ]; then
+ output=$(/usr/bin/qemu-img info $IMAGE_PATH --output=json)
+ if [ $? -ne 0 ]; then
+ echo "qemu-img info returned error"
+ exit 1
+ fi
+
+ IFS=","
+ echo $output | while read -r LINE; do
+ #it is not a valid image if its format is not qcow2.
+ if [ `echo $LINE | awk '$1 == "\"format\":" {print $1 }'` ] && [ `echo $LINE | awk '$2 != "\"qcow2\"" {print $2 }'` ] ; then
+ echo "Invalid format for image $IMAGE_PATH"
+ exit 1
+ fi
+ #it is not a valid image if it has backing-filename
+ if [ `echo $LINE | awk '$1 == "\"backing-filename\":" {print $1 }'` ]; then
+ echo "Image $IMAGE_PATH is invalid because it has a backing file"
+ exit 1
+ fi
+ done
+
IMAGE_EXTENSION="raw"
/usr/bin/qemu-img convert $IMAGE_PATH ${COPY_PATH}.${IMAGE_EXTENSION}
if [ $? -ne 0 ]; then
