php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61036 bcompiler_load_exe gives "Could not find Magic header"
Submitted: 2012-02-10 05:48 UTC Modified: 2017-01-10 07:58 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: chibisuke at web dot de Assigned:
Status: Suspended Package: bcompiler (PECL)
PHP Version: 5.3.10 OS: FreeBSD 9 (amd64)
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: chibisuke at web dot de
New email:
PHP Version: OS:

 

 [2012-02-10 05:48 UTC] chibisuke at web dot de
Description:
------------
a bcompiled php script that has been compiled to into an executable on FreeBSD 9 (amd64) cannot be loaded by bcompiler_load_exe.

After diging a bit into the code

Test script:
---------------
Creating the output file:
<?php
        function main() {
                echo "hello world";
        }

        $fh = fopen("output", "wb");
        $size = filesize("phpe");
        $fr = fopen("phpe", "rb");
        fwrite($fh, fread($fr, $size), $size);
        $startpos = ftell($fh);

        $fh = fopen("output", "w");

        bcompiler_write_header($fh);
        bcompiler_write_class($fh, "test");
        bcompiler_write_function($fh, "main");
        bcompiler_write_footer($fh);
        bcompiler_write_exe_footer($fh, $startpos);
?>
Loading the file:
<?php
        bcompiler_load_exe('output');
        print_r(get_declared_classes());
?>


Expected result:
----------------
> Hello World

Actual result:
--------------
PHP Fatal error:  Could not find Magic header in stream in /root/ad/test.php on line 2

Fatal error: Could not find Magic header in stream in /root/ad/test.php on line 2


Patches

change-4byte-to-dynamic (last revision 2012-02-10 06:04 UTC by chibisuke at web dot de)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-10 05:51 UTC] chibisuke at web dot de
Debug log of the create script:
[DEBUG] read magic: 3c 3f..
[DEBUG]      scalar: 01609bdd (size: 8, name: start)
[DEBUG] STRING: len, string : bcompiler v1.0.2s
[DEBUG]      scalar: 00000011 (size: 8, name: len)
[DEBUG]       STORE: [bcompiler v1.0.2s] (size: 17, name: string)
[DEBUG] DUMP: 62 63 6F 6D 70 69 6C 65 72 20 76 31 2E 30 2E 32 bcompiler v1.0.2
[DEBUG] DUMP: 73                                              s

Debug log of the loader script:
[DEBUG] read magic: 3c 3f..
[DEBUG] read magic: dd 9b..
[DEBUG] move to start: -21
[DEBUG] done seek - try deserialize
[DEBUG] move to end: -25
[DEBUG]      scalar: 00000011 (size: 8, name: &pos)
[DEBUG]      read : 17
[DEBUG] move to start: 17

To me this looks like a x64 bug. 
bcompiler_load_exe seams to be using hardcoded 4 byte offsets for int serialized int values, while they're 8 byte wide.
 [2012-02-10 05:56 UTC] chibisuke at web dot de
Oups... in the create script I forgot a debug line.
here's the correct one:

Creating the output file:
<?php
        function main() {
                echo "hello world";
        }

        $fh = fopen("output", "wb");
        $size = filesize("phpe");
        $fr = fopen("phpe", "rb");
        fwrite($fh, fread($fr, $size), $size);
        $startpos = ftell($fh);

        bcompiler_write_header($fh);
        bcompiler_write_class($fh, "test");
        bcompiler_write_function($fh, "main");
        bcompiler_write_footer($fh);
        bcompiler_write_exe_footer($fh, $startpos);
?>
 [2012-02-10 06:06 UTC] chibisuke at web dot de
k, the attached patch fixes the problem. Thought I'd share it.
 [2017-01-10 07:58 UTC] kalle@php.net
-Status: Open +Status: Suspended
 [2017-01-10 07:58 UTC] kalle@php.net
Suspending this report as the extension have not had a release for almost 6 years.  Please revive this if the extension once again shows life
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC