Skip to content

Commit 7dabc7e

Browse files
authored
Merge pull request #412 from wtn/skip
Stop dropping the invalid byte 0xc1 in skip_nil and the header readers
2 parents 28df651 + c0c5150 commit 7dabc7e

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎ext/msgpack/unpacker.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ void msgpack_unpacker_static_destroy(void)
9595
msgpack_rmem_destroy(&s_stack_rmem);
9696
}
9797

98-
#define HEAD_BYTE_REQUIRED 0xc1
98+
/* outside 0..255 so it never collides with a real byte, including the invalid 0xc1 */
99+
#define HEAD_BYTE_REQUIRED 0x100
99100

100101
static inline bool _msgpack_unpacker_stack_init(msgpack_unpacker_stack_t *stack) {
101102
if (!stack->data) {

‎spec/cruby/unpacker_spec.rb‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,33 @@
6767
unpacker.skip
6868
}.should raise_error(MessagePack::MalformedFormatError)
6969
end
70+
71+
it 'skip_nil keeps invalid byte' do
72+
unpacker.feed("\xc1\x01")
73+
unpacker.skip_nil.should == false
74+
lambda {
75+
unpacker.read
76+
}.should raise_error(MessagePack::MalformedFormatError)
77+
end
78+
79+
it 'read_array_header keeps invalid byte' do
80+
unpacker.feed("\xc1\x01")
81+
lambda {
82+
unpacker.read_array_header
83+
}.should raise_error(MessagePack::UnpackError)
84+
lambda {
85+
unpacker.read
86+
}.should raise_error(MessagePack::MalformedFormatError)
87+
end
88+
89+
it 'read_map_header keeps invalid byte' do
90+
unpacker.feed("\xc1\x01")
91+
lambda {
92+
unpacker.read_map_header
93+
}.should raise_error(MessagePack::UnpackError)
94+
lambda {
95+
unpacker.read
96+
}.should raise_error(MessagePack::MalformedFormatError)
97+
end
7098
end
7199

0 commit comments

Comments
 (0)