This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] FuzzedDataProvider: add ConsumeData method.
ClosedPublic

Authored by Dor1s on Feb 10 2020, 2:25 PM.

Diff Detail

Event Timeline

Dor1s created this revision.Feb 10 2020, 2:25 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptFeb 10 2020, 2:25 PM
Herald added subscribers: llvm-commits, Restricted Project, dberris. · View Herald Transcript
Dor1s added a comment.Feb 10 2020, 2:27 PM

Jonathan @metzman please take a look when you get a chance. I'll add the tests later. Two comments:

  1. ConsumeMemory was requested by the users a few times and I think makes sense
  2. hash is my own idea and I'm not sure it's a good one. What's your opinion?

Thank you!

metzman accepted this revision.Feb 10 2020, 4:23 PM

Mostly LGTM.
What's hash for? To seed an RNG?
I'm not 100% hashing the whole array is the right way to do things but it might be better than nothing.
I guess changing this is possible but not ideal since corpus elements won't map to the same behavior if we change it to say, the last byte or something similar.

compiler-rt/include/fuzzer/FuzzedDataProvider.h
252

I think saying "Not recommended in general" is a bit weird. What's wrong with it for the intended purpose?
maybe say it's the std::hash. When I read "the hash" my first thought was "which? md5? sha1? etc."

255

I think we need to include <functional> to use std::hash right?

256

I would guess this will be a long way off.

This revision is now accepted and ready to land.Feb 10 2020, 4:23 PM
Dor1s updated this revision to Diff 243989.Feb 11 2020, 1:42 PM

remove hash method, rename ConsumeMemory to ConsumeData, add test

Dor1s added a comment.Feb 11 2020, 1:43 PM

Thanks for the review. I can't think of a good application for the hash. Anything I come up with is better to be done either without hashing or even without FDP.

  • Removed the hash
  • Added test
  • Renamed ConsumeMemory to ConsumeData, as the former sounds a bit ambiguous (like memory consumption is more about memory being allocated, while here it's just values being copied, i.e. data)
Dor1s marked 5 inline comments as done.Feb 11 2020, 1:45 PM

I'm gonna rebase and commit, since there isn't much to review compared to the PS#1 (just a test).

compiler-rt/include/fuzzer/FuzzedDataProvider.h
252

yeah, this is one more argument not to add such method, deleted

255

good catch, I've also forgot <> for the template parameter, but anyway it's deleted now.

Dor1s retitled this revision from [compiler-rt] FuzzedDataProvider: add ConsumeMemory and hash methods. to [compiler-rt] FuzzedDataProvider: add ConsumeData method..Feb 11 2020, 1:45 PM
metzman accepted this revision.Feb 11 2020, 1:51 PM

still LGTM

compiler-rt/include/fuzzer/FuzzedDataProvider.h
246

Might be better not to use the same name "Consume" as other methods since this method is used a bit differently than other methods which return their value.

This revision was automatically updated to reflect the committed changes.
Dor1s marked 2 inline comments as done.
Dor1s marked an inline comment as done.Feb 11 2020, 1:55 PM
Dor1s added inline comments.
compiler-rt/include/fuzzer/FuzzedDataProvider.h
246

Hmm... I agree it's different, but what would be a good alternative? Copy or Write are also not very intuitive as the internal pointer gets advanced and the data is in fact being consumed.

Also feels like we could just get rid of the Consume prefix for all the methods, but it's too late now :D

metzman added inline comments.Feb 11 2020, 2:08 PM
compiler-rt/include/fuzzer/FuzzedDataProvider.h
246

Don't have an alternative. Probably best to leave as is.