Skip to content

ScopeIndentSniff causes errors when encountering an unmatched parenthesis #554

@XeroXer

Description

@XeroXer

This is a bug i noticed when running SublimeLinter-phpcs, which copies the content of the current file to a temporary file and runs phpcs on that temporary file.
My CPU went to 100% and freezed my computer, and after digging through the logs I found the problem.

This code:

<?php
/*
$a = array(
    */
);

I know the code is wrong and will trigger syntax errors, but it will also freeze up phpcs.
It will print two errors forever:

PHP Notice:  Undefined index:  in .../PHP_CodeSniffer/CodeSniffer/File.php on line 3431
PHP Notice:  Undefined index:  in .../PHP_CodeSniffer/CodeSniffer/File.php on line 3443

On similar code such as:

<?php
/*
$a = [
    */
];

and:

<?php
/*
if (true) {
    */
}

the checking will work as expected on. So without really checking the source it seems the parentheses triggers the problem.

PHP_CodeSniffer might not be meant as a way to check error code but should using it on a file with syntax errors not work, I don't know.
Might need to rethink using the plugin in that case, just thought I'd report this.

EDIT
Changed line 3430 from:
for ($i = $start; $i >= 0; $i--) {
to:
for ($i = (int) $start; $i >= 0; $i--) {
will end the infinite loop, but not solve the problem fully.
Checking the $start variable shows it being null, which created the infinite loop. Forcing it to an integer instead goes through the code, shows the errors but triggers other notices.

PHP Notice:  Undefined index: parenthesis_opener in .../PHP_CodeSniffer/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php on line 226
PHP Notice:  Undefined index:  in .../PHP_CodeSniffer/CodeSniffer/File.php on line 3431

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions