Skip to content

Commit

Permalink
python: Missing check for string overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
shramov committed Dec 17, 2024
1 parent 6149703 commit 0da804e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion python/test/test_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,16 @@ def test_bytes():
m.f0 = 'abc'

with pytest.raises(ValueError):
m.f0 = b'abc'
m.f1 = 'abc'

m.f2 = 'abc'

with pytest.raises(TypeError):
m.f0 = 1

with pytest.raises(TypeError):
m.f1 = 1

def test_time_point():
scheme = S.Scheme("""yamls://
- name: msg
Expand Down
6 changes: 5 additions & 1 deletion python/tll/scheme.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,11 @@ cdef class FFixedString(FBase):

cdef pack(FFixedString self, v, dest, tail, int tail_offset): return pack_bytes(v, dest, tail, tail_offset)
cdef unpack(FFixedString self, src): return unpack_str(src[:self.size])
cdef convert(FFixedString self, v): return convert_str(v)
cdef convert(FFixedString self, v):
v = convert_str(v)
if len(v) > self.size:
raise ValueError(f"String too long: {len(v)} > {self.size}")
return v
cdef from_string(FFixedString self, str s): return s
_SUBTYPES[(Type.Bytes, SubType.ByteString)] = FFixedString

Expand Down

0 comments on commit 0da804e

Please sign in to comment.