Merge pull request from grasskin:patch-2

PiperOrigin-RevId: 321225578
Change-Id: I6cd6ad172bdc1cc80e24f04ffb86a0483244d929
This commit is contained in:
TensorFlower Gardener 2020-07-14 13:45:38 -07:00
commit c9694660f6

View File

@ -12,6 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==============================================================================*/ ==============================================================================*/
#include <fuzzer/FuzzedDataProvider.h>
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
@ -23,17 +25,23 @@ limitations under the License.
namespace { namespace {
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
uint8_t *byte_data = const_cast<uint8_t *>(data); FuzzedDataProvider fuzzed_data(data, size);
char *char_data = reinterpret_cast<char *>(byte_data);
tensorflow::StringPiece sp(char_data, size); while (fuzzed_data.remaining_bytes() > 0) {
std::string s = fuzzed_data.ConsumeRandomLengthString(25);
tensorflow::StringPiece sp(s);
tensorflow::uint64 val; tensorflow::uint64 val;
const bool leading_digits = const bool leading_digits =
tensorflow::str_util::ConsumeLeadingDigits(&sp, &val); tensorflow::str_util::ConsumeLeadingDigits(&sp, &val);
const char lead_char_consume_digits = *(sp.data());
if (leading_digits) { if (leading_digits) {
if (lead_char_consume_digits >= '0') {
assert(lead_char_consume_digits > '9');
}
assert(val >= 0); assert(val >= 0);
} }
}
return 0; return 0;
} }