Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise Dalli::UnmarshalError on ArgumentError "dump format error (user class)" #1008

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/dalli/protocol/value_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def store(value, req_options, bitflags)
# in current systems
# rubocop:disable Layout/LineLength
TYPE_ERR_REGEXP = %r{needs to have method `_load'|exception class/object expected|instance of IO needed|incompatible marshal file format}.freeze
ARGUMENT_ERR_REGEXP = /undefined class|marshal data too short/.freeze
ARGUMENT_ERR_REGEXP = /undefined class|marshal data too short|dump format error \(user class\)/.freeze
NAME_ERR_STR = 'uninitialized constant'
# rubocop:enable Layout/LineLength

Expand Down
4 changes: 2 additions & 2 deletions test/integration/test_network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

describe 'with a fake server' do
it 'handle connection reset' do
memcached_mock(->(sock) { sock.close }) do
memcached_mock(lambda(&:close)) do
dc = Dalli::Client.new('localhost:19123')
assert_raises Dalli::RingError, message: 'No server available' do
dc.get('abc')
Expand All @@ -25,7 +25,7 @@

it 'handle connection reset with unix socket' do
socket_path = MemcachedMock::UNIX_SOCKET_PATH
memcached_mock(->(sock) { sock.close }, :start_unix, socket_path) do
memcached_mock(lambda(&:close), :start_unix, socket_path) do
dc = Dalli::Client.new(socket_path)
assert_raises Dalli::RingError, message: 'No server available' do
dc.get('abc')
Expand Down
17 changes: 17 additions & 0 deletions test/protocol/test_value_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,23 @@
end
end

describe 'when deserialization raises an ArgumentError for a user class' do
let(:error_message) { 'dump format error (user class)' }
let(:serializer) { Marshal }
# This is a "user class", extending a built-in class String. FooString = Class.new(String)
let(:raw_value) { "\x04\bC:\x0EFooString\"\x00" }

it 'raises UnmarshalError on that user extended class' do
# Note that the class does not match the inheritance in the serialized data.
FooString = Class.new(Hash) # rubocop:disable Lint/ConstantDefinitionInBlock
exception = assert_raises Dalli::UnmarshalError do
vs.retrieve(raw_value, Dalli::Protocol::ValueSerializer::FLAG_SERIALIZED)
end

assert_equal exception.message, "Unable to unmarshal value: #{error_message}"
end
end

describe 'when deserialization raises an ArgumentError for an undefined class' do
let(:error_message) { 'undefined class/module NonexistentClass' }
let(:serializer) { Marshal }
Expand Down