Merge branch 'bugfix/CID-1114601'

This commit is contained in:
Hugo Trippaers 2014-09-19 15:15:33 +02:00
commit e327716b89
3 changed files with 26 additions and 6 deletions

View File

@ -24,4 +24,8 @@ public class InternalErrorException extends ManagementServerException {
super(message); super(message);
} }
public InternalErrorException(String message, Throwable cause) {
super(message, cause);
}
} }

View File

@ -30,4 +30,8 @@ public class ManagementServerException extends CloudException {
super(message); super(message);
} }
public ManagementServerException(String message, Throwable cause) {
super(message, cause);
}
} }

View File

@ -79,13 +79,25 @@ public class VhdProcessor extends AdapterBase implements Processor {
byte[] creatorApp = new byte[4]; byte[] creatorApp = new byte[4];
try { try {
strm = new FileInputStream(vhdFile); strm = new FileInputStream(vhdFile);
strm.skip(info.size - vhdFooterSize + vhdFooterCreatorAppOffset); long skipped = strm.skip(info.size - vhdFooterSize + vhdFooterCreatorAppOffset);
strm.read(creatorApp); if (skipped == -1) {
strm.skip(vhdFooterCurrentSizeOffset - vhdFooterCreatorVerOffset); throw new InternalErrorException("Unexpected end-of-file");
strm.read(currentSize); }
} catch (Exception e) { long read = strm.read(creatorApp);
if (read == -1) {
throw new InternalErrorException("Unexpected end-of-file");
}
skipped = strm.skip(vhdFooterCurrentSizeOffset - vhdFooterCreatorVerOffset);
if (skipped == -1) {
throw new InternalErrorException("Unexpected end-of-file");
}
read = strm.read(currentSize);
if (read == -1) {
throw new InternalErrorException("Unexpected end-of-file");
}
} catch (IOException e) {
s_logger.warn("Unable to read vhd file " + vhdPath, e); s_logger.warn("Unable to read vhd file " + vhdPath, e);
throw new InternalErrorException("Unable to read vhd file " + vhdPath + ": " + e); throw new InternalErrorException("Unable to read vhd file " + vhdPath + ": " + e, e);
} finally { } finally {
if (strm != null) { if (strm != null) {
try { try {