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
358 stars 86 forks source link

Code rarely raises ZeroDivisionError #16

Closed Sonic-The-Hedgehog-LNK1123 closed 4 years ago

Sonic-The-Hedgehog-LNK1123 commented 5 years ago

In the file reedsolo.py at line 499: magnitude = gf_div(y, err_loc_prime)

this will divide by zero if err_loc_prime is zero.

You should add a check for err_loc_prime == 0

like this:

        y = gf_poly_eval(err_eval[::-1], Xi_inv) # numerator of the Forney algorithm (errata evaluator evaluated)
        y = gf_mul(gf_pow(Xi, 1), y)

        if err_loc_prime == 0:
            raise ReedSolomonError("Could not find error magnitude") 

        # Compute the magnitude
        magnitude = gf_div(y, err_loc_prime) # magnitude value of the error, calculated by the Forney algorithm (an equation in fact): dividing the errata evaluator with the errata locator derivative gives us the errata magnitude (ie, value to repair) the ith symbol
        E[err_pos[i]] = magnitude # store the magnitude for this error into the magnitude polynomial
lrq3000 commented 4 years ago

Thank you very much @Sonic-The-Hedgehog-LNK1123 , your fix is now implemented :-)