sile / jsone

Erlang JSON library
MIT License
291 stars 72 forks source link

Small fixes (and their test cases) #24

Closed srenatus closed 7 years ago

srenatus commented 7 years ago

Hey there.

I've taken the fuzzed input data I had lying around and fed it into jsone_decode:decode/1:

-module(jsone_decode_fuzz_tests).

-include_lib("eunit/include/eunit.hrl").

radamsa_test_() ->
    FuzzedSamples = read_fuzzed_samples(),
    [{timeout, 300, input(Input)} || Input <- FuzzedSamples].

input(Input) ->
    {Input, fun() ->
                {ok, Bin} = file:read_file(Input),
                case jsone_decode:decode(Bin) of
                    {ok, _, _} -> ok;
                    {error, _} -> ok;
                    Wat -> ?assertEqual(unlikely, Wat)
                end
            end}.

read_fuzzed_samples() ->
    CasesPath = "/tmp/fuzzed/*", %% out of that dir so rebar won't copy it
    lists:sort(filelib:wildcard(CasesPath)).

After these fixes, it would always return {ok, _, _} or {error, _}, and never throw an exception.

sile commented 7 years ago

LGTM. Thanks for this improvement!