Repository navigation
Improve return type of base64_decode() - #4492
Conversation
2fdb743 to
1b54776
Compare
|
This improves things a bit too much as it breaks analysis of PHPStan itself 😀 The base64 call inside the codebase meant to obfuscate a string so that we don't need to baseline related errors. But now we can un-obfuscate it and actually baseline the errors. |
| $isValidBase64 = TrinaryLogic::lazyExtremeIdentity( | ||
| $constantStrings, | ||
| static function (ConstantStringType $constantString): TrinaryLogic { | ||
| $isValid = base64_decode($constantString->getValue(), true) !== false; |
There was a problem hiding this comment.
base64-decoding any string from within the codebase could skyrocket memory needed by phpstan analysis.
e.g. some codebases contain multi-megabyte base64 representations of images
There was a problem hiding this comment.
Yeah, I'm inclining not doing this at all.
There was a problem hiding this comment.
Would a length-limit help?
There was a problem hiding this comment.
I'm really not sure why would we want to decode literal strings passed to this method at all.
- Detect when the result cannot be false - Correctly treat non-boolean $strict parameter
1b54776 to
2b9b9a9
Compare
|
Thank you! |
|
@ondrejmirtes in the discussion above we concluded we likely don't want base64-decode at static analysis time because it can require lots of memory. now the PR got merged. did you change your opinion or was it merged by mistake? |
|
I understood it's not literal input to literal output, just more precise return type than we had before. Was I wrong? |
|
I just double checked. PHPStan analyzing a file like https://gist.github.com/staabm/01151e74a45d36d30f5a2d5ad4776f5c (with a 50.000 words long b64-encoded inline literal) takes 2 MB more RAM after this PR its not as bad as I though initially. given php-src might get more efficient with base64 in the future it might be good enough. depends on how big the base64 literal-strings are, which people put into their source files |
|
My two cents: If this remains a concern, perhaps doing |
Fix handling of non-bools as
$strictparameter and omitfalsefrom return type when$stringis valid base64.This is useful when constant binary strings are required in code, e.g.:
Related to phpstan/phpstan#7866