Commit 9b82f79
committed
Fix a bug that
`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.Prism.parse_stream may write too much data to internal buffer1 parent ab9412c commit 9b82f79
2 files changed
Lines changed: 52 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
368 | 382 | | |
369 | | - | |
370 | 383 | | |
371 | | - | |
372 | | - | |
373 | | - | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
374 | 397 | | |
375 | | - | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
376 | 405 | | |
377 | | - | |
378 | | - | |
379 | | - | |
| 406 | + | |
| 407 | + | |
380 | 408 | | |
381 | | - | |
382 | | - | |
383 | 409 | | |
384 | 410 | | |
385 | 411 | | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | 412 | | |
391 | 413 | | |
392 | 414 | | |
| |||
426 | 448 | | |
427 | 449 | | |
428 | 450 | | |
| 451 | + | |
429 | 452 | | |
| 453 | + | |
430 | 454 | | |
431 | 455 | | |
432 | 456 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
117 | 131 | | |
118 | 132 | | |
0 commit comments