Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nn_mul_kara causes out-of-bounds reads #16

Closed
percontation opened this issue Jan 29, 2018 · 4 comments
Closed

nn_mul_kara causes out-of-bounds reads #16

percontation opened this issue Jan 29, 2018 · 4 comments

Comments

@percontation
Copy link
Contributor

nn_mul_kara sometimes violates the "bm >= cm" constraint of nn_add_c, potentially leading to invalid memory reads and incorrect results.

The values from this stack trace reveal the issue (i.e. these input parameters to nn_mul_kara seem to meet its input assumptions, but cause a call to nn_add_c that violate nn_add_c's input assumptions):

    frame #4: 0x0000000100034e14 t-nn_subquadratic`nn_add_c(a=0x0000616000007c40, b=0x0000616000007c40, bm=40, c=0x00007fff5fbfe9a0, cm=41, ci=0) + 100 at nn.h:333
    frame #5: 0x0000000100034bb3 t-nn_subquadratic`nn_mul_kara(p=0x0000616000007ba0, a=0x0000613000001020, m=39, b=0x00006110000011e0, n=21) + 4531 at nn_subquadratic.c:63
    frame #6: 0x0000000100002176 t-nn_subquadratic`test_mul_kara + 2710 at t-nn_subquadratic.c:59

Adding ASSERT(bm >= cm) to nn_add_c caused tests failed in multiple places; I'm not sure if nn_mul_kara is the only function violating nn_add_c's input assumptions.

@wbhart
Copy link
Owner

wbhart commented Jan 29, 2018 via email

@percontation
Copy link
Contributor Author

Yeah, no worries. I might indeed attempt to produce a patch at some point. I just figured I'd try you first in case the fix is easy for someone who already understands the code :)

@wbhart
Copy link
Owner

wbhart commented Jan 29, 2018 via email

@wbhart wbhart closed this as completed Jan 29, 2018
@percontation
Copy link
Contributor Author

Awesome, thanks!

Assumedly the reason it wasn't showing up in the tests is that the high limbs of t and p end up zeroed (I assume?), the former wrong length rarely exceeds the actual allocated lengths, and even when it did run off the end of p it was finding a zero in memory there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants