[haiku-commits] haiku: hrev53343 - headers/private/package/hpkg

  • From: Alex von Gluck IV <kallisti5@xxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 5 Aug 2019 11:07:28 -0400 (EDT)

hrev53343 adds 1 changeset to branch 'master'
old head: 02e836dc3c3850e5f3d00bf6b85563d3900c6ec8
new head: 6c331fc7e1e5b9b9273ea4257721397f335093bf
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=6c331fc7e1e5+%5E02e836dc3c38

----------------------------------------------------------------------------

6c331fc7e1e5: kit/package: Error on short file read
  
  * It's safe to assume that if the file is shorter than
    the provided header, things will go poorly.
  * Avoids a random vauge ReadBuffer error.
  * This doesn't fix #15230, but makes the issue clearer.
  
  Change-Id: I3471e6de384a0c9be94049ad891c01be980f7846
  Reviewed-on: https://review.haiku-os.org/c/1679
  Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>

                          [ Alexander von Gluck IV <kallisti5@xxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev53343
Commit:      6c331fc7e1e5b9b9273ea4257721397f335093bf
URL:         https://git.haiku-os.org/haiku/commit/?id=6c331fc7e1e5
Author:      Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>
Date:        Mon Aug  5 13:34:14 2019 UTC
Committer:   Alex von Gluck IV <kallisti5@xxxxxxxxxxx>
Commit-Date: Mon Aug  5 15:07:24 2019 UTC

Ticket:      https://dev.haiku-os.org/ticket/15230

----------------------------------------------------------------------------

1 file changed, 7 insertions(+)
headers/private/package/hpkg/ReaderImplBase.h | 7 +++++++

----------------------------------------------------------------------------

diff --git a/headers/private/package/hpkg/ReaderImplBase.h 
b/headers/private/package/hpkg/ReaderImplBase.h
index 1341a6e495..57f386a2cb 100644
--- a/headers/private/package/hpkg/ReaderImplBase.h
+++ b/headers/private/package/hpkg/ReaderImplBase.h
@@ -451,6 +451,13 @@ ReaderImplBase::Init(BPositionIO* file, bool keepFile, 
Header& header, uint32 fl
                fileSize = -1;
        }
 
+       // validate file is longer than header (when not a stream)
+       if (fileSize >= 0 && fileSize < (off_t)sizeof(header)) {
+               ErrorOutput()->PrintError("Error: Invalid %s file: Length 
shorter than "
+                       "header!\n", fFileType);
+               return B_BAD_DATA;
+       }
+
        // read the header
        if ((error = ReadBuffer(0, &header, sizeof(header))) != B_OK)
                return error;


Other related posts:

  • » [haiku-commits] haiku: hrev53343 - headers/private/package/hpkg - Alex von Gluck IV