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

ConsumeRemainingBytes and ConsumeRemainingBytesAsString should invalidate further usages #102

Open
oggy22 opened this issue Jan 7, 2022 · 1 comment

Comments

@oggy22
Copy link

oggy22 commented Jan 7, 2022

An anti-pattern that may occur is using any methods after calling ConsumeRemainingBytes and ConsumeRemainingBytesAsString. They both consume everything left and no call on the data provider should be allowed after it. This should be prevented by throwing exception on any subsequent call.

@oggy22
Copy link
Author

oggy22 commented Mar 28, 2024

The same should happen when remaining_bytes() returns zero. An example of code is:

FuzzedDataProvider data_provider(data, size);
while (data_provider.remaining_bytes()) {
int number = data_provider.ConsumeIntegral<int32_t>();
}

data_provider.ConsumeAnything();   // at this point data_provider is guaranteed to be empty and this call will always return zero-like object.

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

1 participant