Skip to content

[BUG] PHP Fatal error: Uncaught TypeError: strspn(): Argument #1 ($string) must be of type string, null given in /framework/simplepie/src/Content/Type/Sniffer.php:153 #810

@LaKanDoR

Description

@LaKanDoR

IMPORTANT: If you are posting code or output, please make sure you wrap it with fenced code blocks so that it is readable.

Description

$ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20"); - simplepie/src/Content/Type/Sniffer.php:153

$this->file->body is empty.

Steps to Reproduce

it's maybe a empty resource where the DOM HTML is empty.

Expected Behavior

skip invalid RSS-Source.

Actual Behavior

Fatal error cron job exits.

Possible Solutions

strlen() Check should work to avoid strspn() to crash.

       if(!is_null($this->file->body)) {
        
            $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
            if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html'
                || strtolower(substr($this->file->body, $ws, 5)) === '<html'
                || strtolower(substr($this->file->body, $ws, 7)) === '<script') {
                return 'text/html';
            } elseif (substr($this->file->body, 0, 5) === '%PDF-') {
                return 'application/pdf';
            } elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-') {
                return 'application/postscript';
            } elseif (substr($this->file->body, 0, 6) === 'GIF87a'
                || substr($this->file->body, 0, 6) === 'GIF89a') {
                return 'image/gif';
            } elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") {
                return 'image/png';
            } elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF") {
                return 'image/jpeg';
            } elseif (substr($this->file->body, 0, 2) === "\x42\x4D") {
                return 'image/bmp';
            } elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00") {
                return 'image/vnd.microsoft.icon';
            }
            
            return $this->text_or_binary();
        }

Environment

Debian 10 with PHP 8.2

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions