test_seq.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # coding: utf-8
  2. import io
  3. import pandas.io.msgpack as msgpack
  4. binarydata = bytes(bytearray(range(256)))
  5. def gen_binary_data(idx):
  6. return binarydata[:idx % 300]
  7. def test_exceeding_unpacker_read_size():
  8. dumpf = io.BytesIO()
  9. packer = msgpack.Packer()
  10. NUMBER_OF_STRINGS = 6
  11. read_size = 16
  12. # 5 ok for read_size=16, while 6 glibc detected *** python: double free or
  13. # corruption (fasttop):
  14. # 20 ok for read_size=256, while 25 segfaults / glibc detected *** python:
  15. # double free or corruption (!prev)
  16. # 40 ok for read_size=1024, while 50 introduces errors
  17. # 7000 ok for read_size=1024*1024, while 8000 leads to glibc detected ***
  18. # python: double free or corruption (!prev):
  19. for idx in range(NUMBER_OF_STRINGS):
  20. data = gen_binary_data(idx)
  21. dumpf.write(packer.pack(data))
  22. f = io.BytesIO(dumpf.getvalue())
  23. dumpf.close()
  24. unpacker = msgpack.Unpacker(f, read_size=read_size, use_list=1)
  25. read_count = 0
  26. for idx, o in enumerate(unpacker):
  27. assert type(o) == bytes
  28. assert o == gen_binary_data(idx)
  29. read_count += 1
  30. assert read_count == NUMBER_OF_STRINGS