php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69323 PHP Fatal error: Uncaught exception 'PharException' with message 'unable to se
Submitted: 2015-03-28 23:08 UTC Modified: 2015-03-30 09:43 UTC
From: nazar at mokrynskyi dot com Assigned:
Status: Not a bug Package: PHAR related
PHP Version: 5.6.7 OS: Ubuntu x64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nazar at mokrynskyi dot com
New email:
PHP Version: OS:

 

 [2015-03-28 23:08 UTC] nazar at mokrynskyi dot com
Description:
------------
Test script is very simple, but when I run it - I get:
> PHP Fatal error:  Uncaught exception 'PharException' with message 'unable to seek to start of file

Note, that if we add one file (no matter the same or different) - it works fine, it two (no matter the same or different) - it crashes with exception.

My thoughts are that after unsetting $phar, file is not properly closed and there is some uncleaned cache present.

I can send pull request with this test case added on GitHub.

Test script:
---------------
<?php
ini_set('display_errors', 1);
file_put_contents('test', 'some content');
$phar = new Phar('build.phar');
$phar->addFile('test', 'test');
$phar->addFile('test', 'test2');
unset($phar);
rename('build.phar', 'build2.phar');
$phar = new Phar('build.phar');
$phar->addFile('test', 'test');
echo "ok";

Expected result:
----------------
ok

Actual result:
--------------
Fatal error: Uncaught exception 'PharException' with message 'unable to seek to start of file "test2" while creating new phar "/path/build.phar"' in /path/build.php:10 Stack trace: #0 /path/build.php(10): Phar->addFile('test', 'test') #1 {main} thrown in /path/build.php on line 10

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-30 01:21 UTC] danack@php.net
-Status: Open +Status: Verified
 [2015-03-30 01:21 UTC] danack@php.net
That does seem to be an issue - it's possible with code that doesn't involve unet as well.

function foo() {
    ini_set('display_errors', 1);
    file_put_contents('test', 'some content');
    $phar = new Phar('build.phar');
    $phar->addFile('test', 'test');
    $phar->addFile('test', 'test2');
}

function bar() {
    $phar = new Phar('build.phar');
    $phar->addFile('test', 'test');
    echo "ok";
}

foo();
rename('build.phar', 'build2.phar');
bar();
 [2015-03-30 09:35 UTC] mike@php.net
-Status: Verified +Status: Not a bug
 [2015-03-30 09:35 UTC] mike@php.net
PHARs are cached. F.e. use Phar::unlinkArchive() after rename, to clear that cache entry.
 [2015-03-30 09:43 UTC] nazar at mokrynskyi dot com
@mike, is it possible to add somewhere to documentation?
It is not intuitive at all.
 [2015-04-02 01:47 UTC] danack@php.net
This seems to be a bug to me.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 10:01:31 2024 UTC