Hey all,

I've spent a bunch of time tracking down this issue (which was intermittent at best) and have identified the problem and have a patch for the solution.

Details here: https://bugs.php.net/bug.php?id=60164

The attached patch is against trunk, PHP_5_4, & PHP_5_3.

Seeing as though I've supplied patches in the past (see release notes), that I've spend significant time on understanding the Phar extension, and am able to fix issues there now, I'd like to be the one to commit this patch if internals is in agreement.

So, how about it?

-ralph
Index: trunk/ext/phar/tests/files/stuboflength1041.phar.inc
===================================================================
--- trunk/ext/phar/tests/files/stuboflength1041.phar.inc        (revision 0)
+++ trunk/ext/phar/tests/files/stuboflength1041.phar.inc        (revision 0)
@@ -0,0 +1,21 @@
+<?php
+
+@unlink(__DIR__ . '/stuboflength1041.phar');
+
+$phar = new Phar('./stuboflength1041.phar');
+$phar['a.php'] = 'hi1';
+$phar['b.php'] = 'hi2';
+
+$phar->setStub('<?php
+/***stub of length 1041 including the halt 
compiler*********************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+*********************************************/
+__HALT_COMPILER();');
\ No newline at end of file
Index: trunk/ext/phar/tests/files/stuboflength1041.phar
===================================================================
--- trunk/ext/phar/tests/files/stuboflength1041.phar    (revision 0)
+++ trunk/ext/phar/tests/files/stuboflength1041.phar    (revision 0)
@@ -0,0 +1,14 @@
+<?php
+/***stub of length 1041 including the halt 
compiler*********************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+*********************************************/
+__HALT_COMPILER(); ?>
+Ta.php¼N^“d\¶b.php¼NäÂmŶhi1hi2î,Ý¥¬'þ¹e¸:ÍÄ°7GBMB
\ No newline at end of file
Index: trunk/ext/phar/tests/bug60164.phpt
===================================================================
--- trunk/ext/phar/tests/bug60164.phpt  (revision 0)
+++ trunk/ext/phar/tests/bug60164.phpt  (revision 0)
@@ -0,0 +1,21 @@
+--TEST--
+Phar: verify stub of specific length does not break __HALT_COMPILER(); 
scanning in php
+--SKIPIF--
+<?php
+if (!extension_loaded("phar")) die("skip");
+?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$phar = __DIR__ . '/files/stuboflength1041.phar';
+foreach (new RecursiveIteratorIterator(new Phar($phar, null, 
'stuboflength1041.phar')) as $item) {
+    var_dump($item->getFileName());
+}
+?>
+===DONE===
+--EXPECT--
+string(5) "a.php"
+string(5) "b.php"
+===DONE===
\ No newline at end of file
Index: trunk/ext/phar/phar.c
===================================================================
--- trunk/ext/phar/phar.c       (revision 319002)
+++ trunk/ext/phar/phar.c       (working copy)
@@ -1569,7 +1569,8 @@
        const char zip_magic[] = "PK\x03\x04";
        const char gz_magic[] = "\x1f\x8b\x08";
        const char bz_magic[] = "BZh";
-       char *pos, buffer[1024 + sizeof(token)], test = '\0';
+       char *pos, test = '\0';
+       char buffer[1024 + sizeof(token)]; /* a 1024 byte window + the size of 
the halt_compiler token (moving window) */
        const long readsize = sizeof(buffer) - sizeof(token);
        const long tokenlen = sizeof(token) - 1;
        long halt_offset;
@@ -1717,7 +1718,7 @@
                }
 
                halt_offset += got;
-               memmove(buffer, buffer + tokenlen, got + 1);
+               memmove(buffer, buffer + 1024, tokenlen); /* move the memory 
buffer by the size of the window */
        }
 
        MAPPHAR_ALLOC_FAIL("internal corruption of phar \"%s\" 
(__HALT_COMPILER(); not found)")
Index: branches/PHP_5_3/ext/phar/tests/files/stuboflength1041.phar.inc
===================================================================
--- branches/PHP_5_3/ext/phar/tests/files/stuboflength1041.phar.inc     
(revision 0)
+++ branches/PHP_5_3/ext/phar/tests/files/stuboflength1041.phar.inc     
(revision 0)
@@ -0,0 +1,21 @@
+<?php
+
+@unlink(__DIR__ . '/stuboflength1041.phar');
+
+$phar = new Phar('./stuboflength1041.phar');
+$phar['a.php'] = 'hi1';
+$phar['b.php'] = 'hi2';
+
+$phar->setStub('<?php
+/***stub of length 1041 including the halt 
compiler*********************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+*********************************************/
+__HALT_COMPILER();');
\ No newline at end of file
Index: branches/PHP_5_3/ext/phar/tests/files/stuboflength1041.phar
===================================================================
--- branches/PHP_5_3/ext/phar/tests/files/stuboflength1041.phar (revision 0)
+++ branches/PHP_5_3/ext/phar/tests/files/stuboflength1041.phar (revision 0)
@@ -0,0 +1,14 @@
+<?php
+/***stub of length 1041 including the halt 
compiler*********************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+*********************************************/
+__HALT_COMPILER(); ?>
+Ta.php¼N^“d\¶b.php¼NäÂmŶhi1hi2î,Ý¥¬'þ¹e¸:ÍÄ°7GBMB
\ No newline at end of file
Index: branches/PHP_5_3/ext/phar/tests/bug60164.phpt
===================================================================
--- branches/PHP_5_3/ext/phar/tests/bug60164.phpt       (revision 0)
+++ branches/PHP_5_3/ext/phar/tests/bug60164.phpt       (revision 0)
@@ -0,0 +1,21 @@
+--TEST--
+Phar: verify stub of specific length does not break __HALT_COMPILER(); 
scanning in php
+--SKIPIF--
+<?php
+if (!extension_loaded("phar")) die("skip");
+?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$phar = __DIR__ . '/files/stuboflength1041.phar';
+foreach (new RecursiveIteratorIterator(new Phar($phar, null, 
'stuboflength1041.phar')) as $item) {
+    var_dump($item->getFileName());
+}
+?>
+===DONE===
+--EXPECT--
+string(5) "a.php"
+string(5) "b.php"
+===DONE===
\ No newline at end of file
Index: branches/PHP_5_3/ext/phar/phar.c
===================================================================
--- branches/PHP_5_3/ext/phar/phar.c    (revision 319004)
+++ branches/PHP_5_3/ext/phar/phar.c    (working copy)
@@ -1569,7 +1569,8 @@
        const char zip_magic[] = "PK\x03\x04";
        const char gz_magic[] = "\x1f\x8b\x08";
        const char bz_magic[] = "BZh";
-       char *pos, buffer[1024 + sizeof(token)], test = '\0';
+       char *pos, test = '\0';
+       char buffer[1024 + sizeof(token)]; /* a 1024 byte window + the size of 
the halt_compiler token (moving window) */
        const long readsize = sizeof(buffer) - sizeof(token);
        const long tokenlen = sizeof(token) - 1;
        long halt_offset;
@@ -1717,7 +1718,7 @@
                }
 
                halt_offset += got;
-               memmove(buffer, buffer + tokenlen, got + 1);
+               memmove(buffer, buffer + 1024, tokenlen); /* move the memory 
buffer by the size of the window */
        }
 
        MAPPHAR_ALLOC_FAIL("internal corruption of phar \"%s\" 
(__HALT_COMPILER(); not found)")
Index: branches/PHP_5_4/ext/phar/tests/files/stuboflength1041.phar.inc
===================================================================
--- branches/PHP_5_4/ext/phar/tests/files/stuboflength1041.phar.inc     
(revision 0)
+++ branches/PHP_5_4/ext/phar/tests/files/stuboflength1041.phar.inc     
(revision 0)
@@ -0,0 +1,21 @@
+<?php
+
+@unlink(__DIR__ . '/stuboflength1041.phar');
+
+$phar = new Phar('./stuboflength1041.phar');
+$phar['a.php'] = 'hi1';
+$phar['b.php'] = 'hi2';
+
+$phar->setStub('<?php
+/***stub of length 1041 including the halt 
compiler*********************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+*********************************************/
+__HALT_COMPILER();');
\ No newline at end of file
Index: branches/PHP_5_4/ext/phar/tests/files/stuboflength1041.phar
===================================================================
--- branches/PHP_5_4/ext/phar/tests/files/stuboflength1041.phar (revision 0)
+++ branches/PHP_5_4/ext/phar/tests/files/stuboflength1041.phar (revision 0)
@@ -0,0 +1,14 @@
+<?php
+/***stub of length 1041 including the halt 
compiler*********************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+************************************************************************************************
+*********************************************/
+__HALT_COMPILER(); ?>
+Ta.php¼N^“d\¶b.php¼NäÂmŶhi1hi2î,Ý¥¬'þ¹e¸:ÍÄ°7GBMB
\ No newline at end of file
Index: branches/PHP_5_4/ext/phar/tests/bug60164.phpt
===================================================================
--- branches/PHP_5_4/ext/phar/tests/bug60164.phpt       (revision 0)
+++ branches/PHP_5_4/ext/phar/tests/bug60164.phpt       (revision 0)
@@ -0,0 +1,21 @@
+--TEST--
+Phar: verify stub of specific length does not break __HALT_COMPILER(); 
scanning in php
+--SKIPIF--
+<?php
+if (!extension_loaded("phar")) die("skip");
+?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$phar = __DIR__ . '/files/stuboflength1041.phar';
+foreach (new RecursiveIteratorIterator(new Phar($phar, null, 
'stuboflength1041.phar')) as $item) {
+    var_dump($item->getFileName());
+}
+?>
+===DONE===
+--EXPECT--
+string(5) "a.php"
+string(5) "b.php"
+===DONE===
\ No newline at end of file
Index: branches/PHP_5_4/ext/phar/phar.c
===================================================================
--- branches/PHP_5_4/ext/phar/phar.c    (revision 319004)
+++ branches/PHP_5_4/ext/phar/phar.c    (working copy)
@@ -1569,7 +1569,8 @@
        const char zip_magic[] = "PK\x03\x04";
        const char gz_magic[] = "\x1f\x8b\x08";
        const char bz_magic[] = "BZh";
-       char *pos, buffer[1024 + sizeof(token)], test = '\0';
+       char *pos, test = '\0';
+       char buffer[1024 + sizeof(token)]; /* a 1024 byte window + the size of 
the halt_compiler token (moving window) */
        const long readsize = sizeof(buffer) - sizeof(token);
        const long tokenlen = sizeof(token) - 1;
        long halt_offset;
@@ -1717,7 +1718,7 @@
                }
 
                halt_offset += got;
-               memmove(buffer, buffer + tokenlen, got + 1);
+               memmove(buffer, buffer + 1024, tokenlen); /* move the memory 
buffer by the size of the window */
        }
 
        MAPPHAR_ALLOC_FAIL("internal corruption of phar \"%s\" 
(__HALT_COMPILER(); not found)")
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to