Skip to content

Conversation

@ashm-dev
Copy link
Contributor

@ashm-dev ashm-dev commented Nov 2, 2025

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests.

@bedevere-app
Copy link

bedevere-app bot commented Nov 2, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

@picnixz picnixz changed the title gh-140594: Fix buffer underflow in PyOS_StdioReadline on null bytes gh-140594: Fix buffer overflow when feeding NULL bytes to PyOS_StdioReadline Nov 2, 2025
@picnixz
Copy link
Member

picnixz commented Nov 2, 2025

FTR, a buffer underflow is something entirely different.

@ashm-dev
Copy link
Contributor Author

ashm-dev commented Nov 2, 2025

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Nov 2, 2025

Thanks for making the requested changes!

@picnixz: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from picnixz November 2, 2025 16:45
@bedevere-app
Copy link

bedevere-app bot commented Nov 2, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@ashm-dev
Copy link
Contributor Author

ashm-dev commented Nov 2, 2025

I have made the requested changes; please review again

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Popen seems an overkill.

@bedevere-app
Copy link

bedevere-app bot commented Nov 2, 2025

Thanks for making the requested changes!

@picnixz: please review the changes made to this pull request.

@ashm-dev
Copy link
Contributor Author

ashm-dev commented Nov 3, 2025

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Nov 3, 2025

Thanks for making the requested changes!

@picnixz: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from picnixz November 3, 2025 08:16
@picnixz
Copy link
Member

picnixz commented Nov 3, 2025

By the way, have you tried to reproduce the issue without JIT and with the GIL as I suggested? I didn't check myself so I wondered whether you did so or not and whether you were able to reproduce the bug on main.

@ashm-dev
Copy link
Contributor Author

ashm-dev commented Nov 3, 2025

It reproduces ONLY when built with ASAN; in all other build variants, there’s no error.

I tried many different combinations:
jit + asan
gil + asan
debug + asan
but it only reproduced with a plain ASAN build.

@efimov-mikhail
Copy link
Member

It seems that NEWS entry here is located at Security section.
But issue doesn't have "type-security" label.
We have to decide is it really security issue or not.

Copy link
Contributor

@sergey-miryanov sergey-miryanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Member

@efimov-mikhail efimov-mikhail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -0,0 +1,2 @@
Fix a buffer overflow when a single NULL character is read from the standard input.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a buffer overflow, "just" a read out of bounds.

Suggested change
Fix a buffer overflow when a single NULL character is read from the standard input.
Fix an out of bounds read when a single NUL character is read from the standard input.

}
n += strlen(p + n);
} while (p[n-1] != '\n');
} while (n == 0 || p[n-1] != '\n');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to stop the loop if n==0.

Suggested change
} while (n == 0 || p[n-1] != '\n');
} while (n != 0 && p[n-1] != '\n');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then input like b'\x00spam\nham\nspam\n' will stop early. Is this intended?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure which behavior is the correct behavior honestly.

I suppose that you should call readline again to read spam\n.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds worth it to add a test at least.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then behavior will be different if string starts with NUL byte or has it in the middle. I think we should document this difference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have this conversation here: #140910 (comment).
Current fix seems to be slightly better for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants