Skip to content

Commit a91ed96

Browse files
nirvdrumeregon
authored andcommitted
Prevent polyglot exceptions from being marshaled since we wouldn't be able to restore them properly.
1 parent fee6dd9 commit a91ed96

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Bug fixes:
1313
* Update `Process` methods to use `module_function` (@bjfish).
1414
* Fix `File::Stat`'s `#executable?` and `#executable_real?` predicates that unconditionally returned `true` for a superuser (#2690, @andrykonchin).
1515
* The `strip` option `--keep-section=.llvmbc` is not supported on macOS (#2697, @eregon).
16+
* Disallow the marshaling of polyglot exceptions since we can't properly reconstruct them (@nirvdrum).
1617

1718
Compatibility:
1819

spec/truffle/interop/polyglot/foreign_exception_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@
9090
end
9191
end
9292

93+
it 'cannot be marshaled' do
94+
-> {
95+
Marshal.dump(@foreign)
96+
}.should raise_error(TypeError)
97+
end
98+
9399
describe "when reaching the top-level" do
94100
it "is printed like a Ruby exception" do
95101
out = ruby_exe('raise Truffle::Debug.foreign_exception "main"', args: "2>&1", exit_status: 1, escape: false)

src/main/ruby/truffleruby/core/truffle/polyglot.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,14 @@ def backtrace_locations
312312
def backtrace
313313
backtrace_locations&.map(&:to_s)
314314
end
315+
316+
def marshal_dump
317+
raise TypeError, "TruffleRuby foreign exceptions cannot be dumped: #{message}"
318+
end
319+
320+
def marshal_load(...)
321+
raise TypeError, 'TruffleRuby foreign exceptions cannot be restored'
322+
end
315323
end
316324

317325
module ExecutableTrait

0 commit comments

Comments
 (0)