Bug #11404
closedSegfault when 'throw' occurs while loading a Ruby source file [PATCH]
Description
Dear Ruby people,
Here is a fix for a segfault which can occur when requiring a Ruby source file inside a Timeout.timeout {} block. This may seem like a strange thing
to do, but it can easily happen unintentionally if you use libraries which 'autoload' their source files (like RSpec, Rails, etc).
I have observed this segfault in MRI 2.1.2 and 2.3.0.
Thanks,
Alex Dowad
Files
Updated by nobu (Nobuyoshi Nakada) over 9 years ago
- Status changed from Open to Closed
Applied in changeset r51439.
load.c: avoid segfault when 'throw' occurs in the middle of rb_load_file_str
How can a 'throw' happen while the current thread is reading a Ruby source file
from disk and parsing it? It can happen if another thread calls Thread#raise,
and passes an Exception object which responds to #exception, and the custom #exception
method calls Kernel#throw.
In practice, this is most likely to happen if you combine the use of autoload and
Timeout.timeout.
An extra check is required to avoid a segfault in this case.
- load.c (rb_load_internal0): extra check before returning TAG_RAISE when a
non-local transfer of control happens while loading and parsing a Ruby source file.
[ruby-core:70169] [Bug #11404]
Updated by nobu (Nobuyoshi Nakada) over 9 years ago
- Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED
Updated by nagachika (Tomoyuki Chikanaga) about 9 years ago
- Related to Bug #11481: Segmentation fault when thread is killed during `require`. added
Updated by nagachika (Tomoyuki Chikanaga) about 9 years ago
- Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: DONE
r51292, r51439 and r51440 were backported into ruby_2_2
branch at r52655.
r51292 seems required to r51440 works well.
Updated by nagachika (Tomoyuki Chikanaga) about 9 years ago
Backport r51445 into ruby_2_2
branch at r52661 to suppress warning in CI.