Actions
Bug #22271
openRuby::Box fails to load C extensions from deep paths (temporary file name exceeds NAME_MAX)
Bug #22271:
Ruby::Box fails to load C extensions from deep paths (temporary file name exceeds NAME_MAX)
Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 4.1.0dev (2026-08-27T10:27:15Z master 89d3b11eac) +YJIT +MN +PRISM [arm64-darwin27]
Description
When a C extension is required inside a Ruby::Box, the temporary copy is named by flattening the full source path into a single file name (/ replaced with +). If the extension lives under a deep path, such as a long BUNDLE_PATH, that single name exceeds NAME_MAX (255 bytes on Linux and macOS) and open(2) fails with ENAMETOOLONG:
LoadError: can't prepare the extension file for Ruby Box (/tmp/_ruby_box_p123_3_+very+deep+...+date_core.so from /very/deep/.../date_core.so): can't open the file to write
Reproduction, from a build tree:
deep=/tmp/$(printf 'd%.0s' {1..90})/$(printf 'e%.0s' {1..90})/$(printf 'f%.0s' {1..90})
mkdir -p $deep
cp .ext/x86_64-linux/date_core.so $deep/
RUBY_BOX=1 ./ruby -e "require '$deep/date_core'"
I propose to stop embedding the source path in the file name: copy extensions into a process-private 0700 directory with an unpredictable name, and name each copy with a short per-process sequence number plus the basename. This also fixes #22110 (predictable temporary file names allow a local DoS).
Pull request: https://github.com/ruby/ruby/pull/18536
No data to display
Actions