From 3393a17c8f5b477c04c7e45e34b451ef5ba1667f Mon Sep 17 00:00:00 2001 From: Volker Ruppert Date: Tue, 14 Oct 2014 21:39:05 +0000 Subject: [PATCH] Fixed crash when using a "fixed" type VPC image. --- bochs/iodev/hdimage/vpc-img.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bochs/iodev/hdimage/vpc-img.cc b/bochs/iodev/hdimage/vpc-img.cc index d6cbe8c51..133d99b12 100644 --- a/bochs/iodev/hdimage/vpc-img.cc +++ b/bochs/iodev/hdimage/vpc-img.cc @@ -91,7 +91,7 @@ int vpc_image_t::open(const char* _pathname, int flags) vhd_dyndisk_header_t *dyndisk_header; Bit8u buf[HEADER_SIZE]; Bit32u checksum; - Bit64u imgsize = 0; + Bit64u offset = 0, imgsize = 0; int disk_type; pathname = _pathname; @@ -110,16 +110,20 @@ int vpc_image_t::open(const char* _pathname, int flags) BX_ERROR(("VPC: signature missed in file '%s'", _pathname)); return -1; } + } else if (disk_type == VHD_FIXED) { + offset = imgsize - HEADER_SIZE; } - if (bx_read_image(fd, 0, (char*)footer_buf, HEADER_SIZE) != HEADER_SIZE) { + if (bx_read_image(fd, offset, (char*)footer_buf, HEADER_SIZE) != HEADER_SIZE) { return -1; } footer = (vhd_footer_t*)footer_buf; checksum = be32_to_cpu(footer->checksum); footer->checksum = 0; - if (vpc_checksum(footer_buf, HEADER_SIZE) != checksum) + if (vpc_checksum(footer_buf, HEADER_SIZE) != checksum) { BX_ERROR(("The header checksum of '%s' is incorrect", pathname)); + return -1; + } // Write 'checksum' back to footer, or else will leave it with zero. footer->checksum = be32_to_cpu(checksum);