tufanbarisyildirim / php-apk-parser

Read basic info about an application from .apk file.
http://tufanbarisyildirim.github.io/php-apk-parser/
Other
336 stars 148 forks source link

Error Facebook #110

Open CrhistopherDiaz opened 1 year ago

CrhistopherDiaz commented 1 year ago

when trying to obtain the data of the facebook or messenger application gives this error An uncaught Exception was encountered Type: RuntimeException

Message: Failed to read 2 bytes

Filename: \vendor\tufanbarisyildirim\php-apk-parser\lib\ApkParser\SeekableStream.php

Line Number: 146

Qplaze commented 7 months ago

I have the same problem on two files. Not facebook app. Some are processed normally and some cause this error.

public function read($length = 1)
{
    // Protect against 0 byte reads when an EOF
    if ($length < 0) {
        throw new \RuntimeException('Length cannot be negative');
    }
    if ($length == 0) {
        return '';
    }

    $bytes = fread($this->stream, $length);
    if (false === $bytes || strlen($bytes) != $length) {
        return 0; //MY DIRTY FIX
        throw new \RuntimeException('Failed to read ' . $length . ' bytes');
    }
    return $bytes;
}

I examined the stream dump at this moment, and received information that the end of the file had been reached. However, there was an attempt to read two more bytes. After my crude fix, the file was read normally and all information was received. It may be worth studying this situation in more detail.

File causing the error: https://drive.google.com/file/d/1qAYe7cwR_wGjr9TnqhznFg7GD1RE726y/view?usp=sharing

tufanbarisyildirim commented 7 months ago

thanks for extra information @Qplaze I will try to dig a bit more