2

Since CPython is implemented in C, when it reads a line from stdin, if the line exceeds whatever is the default size given to the string being read by the interpreter, would it cause a buffer overflow or does Python handle it?

1
  • FWIW, you can see the C source of raw_input here, although I guess you'd also need to read about the GNU readline function too, since raw_input uses that if it's available. Commented Mar 8, 2016 at 3:22

1 Answer 1

7

Python dynamically sizes the string; it's not vulnerable to an overflow (though if the input is huge, it could raise a MemoryError when it can't expand the buffer further).

Python reads the input in chunks, and grows the buffer if it fills the buffer without finding a newline before reading another chunk.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.