From b86d48168233bc9e7ef9d0f92298c7f2a5554c85 Mon Sep 17 00:00:00 2001
From: Paul Duncan <pabs@pablotron.org>
Date: Sun, 2 Sep 2018 18:57:45 -0400
Subject: clean up length checks

---
 src/ZipStream.php | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

(limited to 'src/ZipStream.php')

diff --git a/src/ZipStream.php b/src/ZipStream.php
index 9412438..4b2e8d5 100644
--- a/src/ZipStream.php
+++ b/src/ZipStream.php
@@ -774,6 +774,12 @@ final class Entry {
     $this->time = $time;
     $this->comment = $comment;
 
+    # check comment length
+    if (strlen($comment) >= 0xFFFF) {
+      $this->state = self::ENTRY_STATE_ERROR;
+      throw new Error('comment too long');
+    }
+
     $this->uncompressed_size = 0;
     $this->compressed_size = 0;
     $this->len = 0;
@@ -1078,7 +1084,7 @@ final class Entry {
     }
 
     # check for long path
-    if (strlen($path) > 65535) {
+    if (strlen($path) >= 0xFFFF) {
       throw new PathError($path, "path too long");
     }
 
@@ -1539,7 +1545,7 @@ final class ZipStream {
 
     # get comment, check length
     $comment = $this->args['comment'];
-    if (strlen($comment) >= 65535) {
+    if (strlen($comment) >= 0xFFFF) {
       throw new Error('comment too long');
     }
 
-- 
cgit v1.2.3