-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-16695: phar:// tar parser and zero-length file header blocks #16700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,9 +254,8 @@ int phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, char *alia | |
entry.is_tar = 1; | ||
entry.is_crc_checked = 1; | ||
entry.phar = myphar; | ||
pos += sizeof(buf); | ||
|
||
do { | ||
while (true) { | ||
phar_entry_info *newentry; | ||
|
||
pos = php_stream_tell(fp); | ||
|
@@ -597,6 +596,11 @@ int phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, char *alia | |
} | ||
} | ||
|
||
/* Only read next header if we're not yet at the end */ | ||
if (php_stream_tell(fp) == totalsize) { | ||
break; | ||
} | ||
|
||
read = php_stream_read(fp, buf, sizeof(buf)); | ||
|
||
if (read != sizeof(buf)) { | ||
|
@@ -607,7 +611,7 @@ int phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, char *alia | |
phar_destroy_phar_data(myphar); | ||
return FAILURE; | ||
} | ||
} while (!php_stream_eof(fp)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it a problem then that the eof test has been removed? Here now 261: Probably can be moved to now 258 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nielsdos Thank you for the clarification. |
||
} | ||
|
||
if (zend_hash_str_exists(&(myphar->manifest), ".phar/stub.php", sizeof(".phar/stub.php")-1)) { | ||
myphar->is_data = 0; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--TEST-- | ||
GH-16695 (phar:// tar parser and zero-length file header blocks) | ||
--CREDITS-- | ||
hakre | ||
Comment on lines
+3
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have read this in CONTRIBUTING.md:
ref: 7514b5d ("Mention that zend_parse_parameters should not be tested", 2019-07-07) at least fyi @nielsdos , if you consider this and you need a user/email for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I know the CONTRIBUTING doc says that, but I find it a stupid rule because the Co-authored-by tag is not granular. (it's barely a rule imo due to the weak wording). However, a big chunk of the patch is tests of yours so I'll add a Co-authored-by tag upon merging. |
||
--EXTENSIONS-- | ||
phar | ||
--INI-- | ||
phar.require_hash=0 | ||
--FILE-- | ||
<?php | ||
|
||
$reportTar = __DIR__.'/gh16695_1.tmp'; | ||
|
||
$length = file_put_contents($reportTar, base64_decode('dGxzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAwMDA3MDAAMDAwMDAwMAAwMDAwMDAwADAwMDAwMDAwMDAwADAwMDAwMDAwMDAwADAwNzcxNgAgNQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB1c3RhcgAwMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwMDAwMDAwADAwMDAwMDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=')); | ||
var_dump($length); | ||
$buffer = file_get_contents("phar://$reportTar/tls"); | ||
var_dump($buffer); | ||
|
||
?> | ||
--CLEAN-- | ||
<?php | ||
@unlink(__DIR__.'/gh16695_1.tmp'); | ||
?> | ||
--EXPECTF-- | ||
int(512) | ||
|
||
Warning: file_get_contents(%stls): Failed to open stream: phar error: path "tls" is a directory in %s on line %d | ||
bool(false) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--TEST-- | ||
GH-16695 (phar:// tar parser and zero-length file header blocks) | ||
--CREDITS-- | ||
hakre | ||
--EXTENSIONS-- | ||
phar | ||
--INI-- | ||
phar.require_hash=0 | ||
--FILE-- | ||
<?php | ||
|
||
$reportTar = __DIR__.'/gh16695_2.tmp'; | ||
|
||
$length = file_put_contents($reportTar, base64_decode('bWV0YS5qc29uAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAwMDA2NDQAMDAwMDAwMAAwMDAwMDAwADAwMDAwMDAwMTcyADAwMDAwMDAwMDAwADAxMTAyNgAgMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB1c3RhcgAwMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwMDAwMDA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695_2.tmp'); | ||
?> | ||
--EXPECT-- | ||
int(1024) | ||
string(122) "{"Name":"default","Metadata":{},"Endpoints":{"docker":{"Host":"unix:///run/user/1000/docker.sock","SkipTLSVerify":false}}}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--TEST-- | ||
GH-16695 (phar:// tar parser and zero-length file header blocks) | ||
--CREDITS-- | ||
hakre | ||
--EXTENSIONS-- | ||
phar | ||
--INI-- | ||
phar.require_hash=0 | ||
--FILE-- | ||
<?php | ||
|
||
$reportTar = __DIR__.'/gh16695_3.tmp'; | ||
|
||
$length = file_put_contents($reportTar, base64_decode('dGxzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAwMDA3MDAAMDAwMDAwMAAwMDAwMDAwADAwMDAwMDAwMDAwADAwMDAwMDAwMDAwADAwNzcxMQAgMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB1c3RhcgAwMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwMDAwMDAwADAwMDAwMDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=')); | ||
var_dump($length); | ||
$buffer = file_get_contents("phar://$reportTar/tls"); | ||
var_dump($buffer); | ||
|
||
?> | ||
--CLEAN-- | ||
<?php | ||
@unlink(__DIR__.'/gh16695_3.tmp'); | ||
?> | ||
--EXPECT-- | ||
int(512) | ||
string(0) "" |
Uh oh!
There was an error while loading. Please reload this page.