Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for null byte at the time of writing a file. #966

Merged

Conversation

damien-biasotto
Copy link
Contributor

Good afternoon everyone,

I decided to tackle the #959 issue, by adding a byte null check in the protected method _IsValidSource.

However, I introduced a new behaviour, I arbitrarily decided to flag any strings that contain a null byte character as invalid (for safety reasons).

Then removed any null byte related error suppressors.

I'm not sure what are the guidelines for Pull Requests. Shall I provide a unit test to highlight this change?

when the source is a string and treat it as invalid
if it contains a null byte.

Also removed any error suppressors linked to null byte issue.
@tmotyl
Copy link
Contributor

tmotyl commented May 11, 2020

what else can cause a warning except for the null byte?

@damien-biasotto
Copy link
Contributor Author

what else can cause a warning except for the null byte?

Well, the documentation is not really exhaustive :

Upon failure, an E_WARNING is emitted.

I'd assume if you're not passing a string nor a resource?

@sreichel sreichel added the Component: lib/Varien Relates to lib/Varien label Jun 5, 2020
@colinmollenhour colinmollenhour merged commit ff4c299 into OpenMage:1.9.4.x Jun 11, 2020
@sreichel sreichel added this to the Release 19.4.4 milestone Jun 26, 2020
@tmotyl
Copy link
Contributor

tmotyl commented Jul 1, 2020

hmm seems this change introduced an issue: #1084
How can it be possible that the problem was not caught by linter?

@sreichel
Copy link
Contributor

sreichel commented Jul 1, 2020

@tmotyl this is no problem with linter, it's a problem with reviews ... :(

I've checked https://www.php.net/manual/en/security.filesystem.nullbytes.php, but did not see the typo in that PR AND it was not really tested. Varien_Io_File::write() is only used in a few places so this does not popup during normal frontend/backend tests.

A clear description, steps to reproduce and maybe a code snippet (if easier) should be mandatory.

@damien-biasotto damien-biasotto deleted the GH-959-null-byte-check branch July 1, 2020 23:57
@damien-biasotto
Copy link
Contributor Author

Oh my, I'm really sorry guys. I don't know how i didn't catch that.

@Flyingmana
Copy link
Contributor

@tmotyl I added an Issue for this, I also think we should have a static analyser, which can find such a case.
#1087

The current one did not catch it, as we just check for syntax error, and technically this is not a syntax error.

@digitalpianism
Copy link
Contributor

I made a PR to address the bug that was introduced by that change: #1302

@Tomasz-Silpion
Copy link
Contributor

After hours of debug why our image import has stopped to work what was spotted more than 2 weeks from OpenMage update I got into the same Varien_Io_File _IsValidSource method $src, chr(0) check that fails on base64 content. Replacing the class with @digitalpianism patch has solved the problem. @damien-biasotto @tmotyl can you review the change and merge it for the next release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants