GithubHelp home page GithubHelp logo

Comments (8)

PierwszyTV avatar PierwszyTV commented on September 12, 2024

I've checked it again, and instead of @$this->native(), just put it into try-catch block and it will enough solution.

Screenshot 2022-04-14 at 11 24 01

from bypass-finals.

PierwszyTV avatar PierwszyTV commented on September 12, 2024

@dg Is it possible to fix it soon? Your package is really useful, but without these changes I cannot use it anymore. :(

from bypass-finals.

dg avatar dg commented on September 12, 2024

That's strange that it doesn't work, because there is a test for that and it passes even in PHP 8.0

Assert::false(is_file('unknown'));

from bypass-finals.

dmitryuk avatar dmitryuk commented on September 12, 2024
public function url_stat(string $path, int $flags)
	{
		$func = $flags & STREAM_URL_STAT_LINK ? 'lstat' : 'stat';
		return $flags & STREAM_URL_STAT_QUIET
			? @$this->native($func, $path)
			: $this->native($func, $path);
	}

@PierwszyTV, current implementation url_stat uses error control operator "@" and gets PHP_STREAM_URL_STAT_QUIET flag for is_file function (see https://github.com/php/php-src/blob/master/ext/standard/filestat.c#L793)

So exception can't be thrown
Please provide more info for debug

from bypass-finals.

dmitryuk avatar dmitryuk commented on September 12, 2024

Finally I found a way how to reproduce a bug.
Try the following code:

(new SplFileInfo('filename'))->isFile()

Result: RuntimeException: stat(): stat failed for filename
SplFileInfo::isFile can't throw an exception by guide (link)

@dg any thought how to resolve bug?

from bypass-finals.

dmitryuk avatar dmitryuk commented on September 12, 2024

Please check https://github.com/dg/bypass-finals/pull/34/files

from bypass-finals.

milo avatar milo commented on September 12, 2024

@dg This is indeed strange. With one liners on Windows with PHP 8.1.0

$ php -n -r 'require __DIR__ . "/vendor/autoload.php"; DG\BypassFinals::enable(); stat("filename");'

Warning: stat(): stat failed for filename in D:\Web\dev\bypass-finals\src\BypassFinals.php on line 247
Warning: stat(): stat failed for filename in Command line code on line 1

but

$ php -n -r 'require __DIR__ . "/vendor/autoload.php"; DG\BypassFinals::enable(); (new SplFileInfo("filename"))->isFile();'

Fatal error: Uncaught RuntimeException: stat(): stat failed for filename in D:\Web\dev\bypass-finals\src\BypassFinals.php:247
Stack trace:
#0 D:\Web\dev\bypass-finals\src\BypassFinals.php(247): stat('filename')
#1 D:\Web\dev\bypass-finals\src\BypassFinals.php(238): DG\BypassFinals->native('stat', 'filename')
#2 [internal function]: DG\BypassFinals->url_stat('filename', 6)
#3 Command line code(1): SplFileInfo->isFile()
#4 {main}
  thrown in D:\Web\dev\bypass-finals\src\BypassFinals.php on line 247

Looks like an SPL throws an exception. Similar case described here: https://stackoverflow.com/questions/25296178/why-would-phps-stat-throw-a-runtimeexception

Didn't find any PHP bug.

from bypass-finals.

dg avatar dg commented on September 12, 2024

@milo It normally changes the error handler 🤦‍♂️ (in spl_directory.c)

	zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);\
	php_stat(intern->file_name, func_num, return_value); \
	zend_restore_error_handling(&error_handling); \

from bypass-finals.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.