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

blockchain: Implement stricter bounds checking. #1825

Merged
merged 2 commits into from
Aug 14, 2019

Conversation

aarcamp
Copy link
Contributor

@aarcamp aarcamp commented Aug 8, 2019

This updates the deserialization logic underneath the decodeSpentTxOut function to be more robust, including the addition of explicit bounds checks to prevent panics. In at least one case (txVersion parsing), existing bounds checks were incorrect (e.g., testing for impossible conditions).

A minor rearrangement was also done to eliminate one call to the decodeFlagsFullySpent helper.

Although empty scripts are permitted, decodeCompressedTxOut was missing logic to ensure the script version field actually exists (defaulting to 0x00 only via Golang variable initialization).

To support these changes, the TestStxoDecodeErrors test suite was updated to more closely match the updated logic, and to add new tests for error conditions.

According to "go test -coverprofile", coverage for chainio.go increased from 84.0% to 84.4%.

@davecgh davecgh added this to the 1.5.0 milestone Aug 8, 2019
Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice job on this! I only spotted one potential issue and left an inline comment.

In addition to thoroughly reviewing the changes to the code itself, I also manually went through all of the newly added tests to verify they lined up with the comments and were hitting the expected error paths.

blockchain/chainio.go Outdated Show resolved Hide resolved
@davecgh davecgh changed the title blockchain: Implement stricter bounds checking during transaction spe… blockchain: Implement stricter bounds checking. Aug 14, 2019
Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I'll squash it into a single commit during the merge.

@davecgh davecgh merged commit b9b863f into decred:master Aug 14, 2019
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

Successfully merging this pull request may close these issues.

2 participants