You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix a bug that Prism.parse_stream may write too much data to internal buffer
`pm_source_stream_read()` has 4096 bytes internal buffer to read a
line:
https://github.com/ruby/prism/blob/39fb41f06e5f4ccbe1783122fa8a4470e09dfcfe/src/source.c#L368-L369
It uses `gets(4095)` to read the next chunk to the buffer:
https://github.com/ruby/prism/blob/39fb41f06e5f4ccbe1783122fa8a4470e09dfcfe/ext/prism/extension.c#L1076
But `gets(4095)` may read 4095 or more data when the character at 4095
is a multi-byte character. In the case, `parse_stream_fgets()` writes
4097 or more data to the buffer.
We can avoid it by increasing internal buffer size to `4096 + 6` where
`6` is the max character length in all available encodings. We can
reduce it by using `stream.external_encoding` and `rb_enc_mbmaxlen()`
but it may slow down. So I used constant `6` in this change.
This also changes `pm_source_stream_fgets_t`'s return type to
`int` (read bytes) from `char *` (read data) to reduce needless length
check by caller.
0 commit comments