cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject git commit: updated refs/heads/bugfix/CID-1114601 to 4ad2734
Date Fri, 19 Sep 2014 12:29:14 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/bugfix/CID-1114601 [created] 4ad273457


CID-1114601 to 1114604 Recommended practice is to test the result of
skip and read for EOF

Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4ad27345
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4ad27345
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4ad27345

Branch: refs/heads/bugfix/CID-1114601
Commit: 4ad2734576481f09a3f5ded3d80e9e938dbac5f8
Parents: 90df7cf
Author: Hugo Trippaers <htrippaers@schubergphilis.com>
Authored: Fri Sep 19 14:29:01 2014 +0200
Committer: Hugo Trippaers <htrippaers@schubergphilis.com>
Committed: Fri Sep 19 14:29:01 2014 +0200

----------------------------------------------------------------------
 .../cloud/exception/InternalErrorException.java |  4 ++++
 .../exception/ManagementServerException.java    |  4 ++++
 .../cloud/storage/template/VhdProcessor.java    | 24 +++++++++++++++-----
 3 files changed, 26 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4ad27345/api/src/com/cloud/exception/InternalErrorException.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/exception/InternalErrorException.java b/api/src/com/cloud/exception/InternalErrorException.java
index 8404011..efb68d4 100644
--- a/api/src/com/cloud/exception/InternalErrorException.java
+++ b/api/src/com/cloud/exception/InternalErrorException.java
@@ -24,4 +24,8 @@ public class InternalErrorException extends ManagementServerException {
         super(message);
     }
 
+    public InternalErrorException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4ad27345/api/src/com/cloud/exception/ManagementServerException.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/exception/ManagementServerException.java b/api/src/com/cloud/exception/ManagementServerException.java
index c8a106a..86fd233 100644
--- a/api/src/com/cloud/exception/ManagementServerException.java
+++ b/api/src/com/cloud/exception/ManagementServerException.java
@@ -30,4 +30,8 @@ public class ManagementServerException extends CloudException {
         super(message);
     }
 
+    public ManagementServerException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4ad27345/core/src/com/cloud/storage/template/VhdProcessor.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/storage/template/VhdProcessor.java b/core/src/com/cloud/storage/template/VhdProcessor.java
index aff2942..875376f 100644
--- a/core/src/com/cloud/storage/template/VhdProcessor.java
+++ b/core/src/com/cloud/storage/template/VhdProcessor.java
@@ -79,13 +79,25 @@ public class VhdProcessor extends AdapterBase implements Processor {
         byte[] creatorApp = new byte[4];
         try {
             strm = new FileInputStream(vhdFile);
-            strm.skip(info.size - vhdFooterSize + vhdFooterCreatorAppOffset);
-            strm.read(creatorApp);
-            strm.skip(vhdFooterCurrentSizeOffset - vhdFooterCreatorVerOffset);
-            strm.read(currentSize);
-        } catch (Exception e) {
+            long skipped = strm.skip(info.size - vhdFooterSize + vhdFooterCreatorAppOffset);
+            if (skipped == -1) {
+                throw new InternalErrorException("Unexpected end-of-file");
+            }
+            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);
-            throw new InternalErrorException("Unable to read vhd file " + vhdPath + ": "
+ e);
+            throw new InternalErrorException("Unable to read vhd file " + vhdPath + ": "
+ e, e);
         } finally {
             if (strm != null) {
                 try {


Mime
View raw message