tomerfiliba-org / reedsolomon

⏳🛡 Pythonic universal errors-and-erasures Reed-Solomon codec to protect your data from errors and bitrot. Includes a future-proof zero-dependencies pure-python implementation 🔮 and an optional speed-optimized Cython/C extension 🚀
http://pypi.python.org/pypi/reedsolo
Other
351 stars 86 forks source link

Encoder returns empty array #34

Closed za3k closed 1 year ago

za3k commented 3 years ago

This code:

import reedsolo
reedsolo.RSCodec(300).encode(b'a')

Returns bytearray(b'') on my computer. Adjusting the number down causes it to return something.

za3k commented 3 years ago

Oh also, in case it's an issue with potential string lengths, reedsolo.RSCodec(300, c_exp=12).encode(b'a') instead outputs:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/site-packages/reedsolo.py", line 893, in encode
    enc.extend(rs_encode_msg(chunk, self.nsym, fcr=self.fcr, generator=self.generator, gen=self.gen[nsym]))
  File "/usr/lib/python3.9/site-packages/reedsolo.py", line 514, in rs_encode_msg
    msg_in = _bytearray(msg_in)
  File "/usr/lib/python3.9/site-packages/reedsolo.py", line 279, in _bytearray
    return array("i", obj)
ValueError: bytes length not a multiple of item size
lrq3000 commented 1 year ago

About your first question, it's an uncaught error but it's normal, this happens because you initialized RSCodec with too many ECC symbols (300) when by default the max total message length nsize=255. Now there will be an error message.

About your second question, this was indeed a bug, which was kindly fixed by someone else in #46 and is now merged, so this bug does not happen anymore.

za3k commented 1 year ago

Thanks for adding an error