-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix GH-18120: Honor FILE_SKIP_EMPTY_LINES even when FILE_IGNORE_NEW_LINES is not set
#19346
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
base: master
Are you sure you want to change the base?
Conversation
0294ac1 to
feea545
Compare
feea545 to
c783b4b
Compare
c783b4b to
95211df
Compare
|
Friendly ping @DanielEScherzer @nielsdos as you participated on the issue 🙂 |
|
I'll play with this tomorrow or so. Note that this is fixing long standing behaviour, so targeting 8.5/master is likely more appropriate. |
|
^ what @nielsdos said about not targeting 8.3, but wearing my release manager hat I don't think 8.5 is appropriate |
<?php
$test_file = __DIR__ . "/file_skip_empty_lines.tmp";
$test_data = "\r";
file_put_contents($test_file, $test_data);
$lines = file($test_file, FILE_SKIP_EMPTY_LINES);
var_dump($lines);
$test_data = "\r\r";
file_put_contents($test_file, $test_data);
$lines = file($test_file, FILE_SKIP_EMPTY_LINES);
var_dump($lines);produces: which seems incorrect to me. Can you explain whether this is the desired behaviour? |
95211df to
25718ef
Compare
…_NEW_LINES` is not set
25718ef to
43d24d1
Compare
d8ff4fd to
daf2b51
Compare
|
@ndossche I addressed your concern and updated the test file as well. Also, I rebased on master as suggested. |
ext/standard/file.c
Outdated
| size_t eol_len = 1; | ||
|
|
||
| if (eol_marker == '\n') { | ||
| if (p >= ZSTR_VAL(target_buf) + 2 && *(p - 2) == '\r' && *(p - 1) == '\n') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think target_buf has any guarantees about its length, so ZSTR_VAL(target_buf) + 2 may point out of bounds. However, doing pointer arithmetic that results in a pointer more than 1 byte out of bounds is undefined behaviour.
Use ZSTR_VAL(target_buf) - p >= 2 instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the correct condition is p - ZSTR_VAL(target_buf) >= 2. PR updated 🙂
daf2b51 to
f0e3236
Compare
Fix #18120
Allows to use
FILE_SKIP_EMPTY_LINESwithoutFILE_IGNORE_NEW_LINES: