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

Problem found in DataItemBits::getBits(.....) #19

Closed
imromero opened this issue Feb 11, 2016 · 1 comment
Closed

Problem found in DataItemBits::getBits(.....) #19

imromero opened this issue Feb 11, 2016 · 1 comment

Comments

@imromero
Copy link

Dear All

I have found a problem when DataItemBits::getUnsigned calls DataItemBits::getBits with (for example) the next parameteres:

unsigned char* DataItemBits::getBits( [pData], bytes=2, frombit=9, tobit 16)

numberOfBytes has the value 1

At the end of the method, when running the intruction
_pTmp =_pTmp<< (8-outbits);
pTmp is pointing a memory position with address pVal+1, that is wrong, because pVal was initialized with memset(pVal, 0, numberOfBytes);

When the caller method (GetUnsigned) try to delete pVal, it crashes.
I have applied a very basic solution to protect this situation:

if(pVal+numberOfBytes-1>=pTmp)
_pTmp =_pTmp<< (8-outbits);
return pVal;

Thank you very much

Best Regards
Nacho

@dsalantic
Copy link
Contributor

Yes, that was a serious bug. Thank you for your contribution. It is fixed now.

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