File: 05-fuzzing.lua

package info (click to toggle)
lua-messagepack 0.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 364 kB
  • sloc: makefile: 108
file content (35 lines) | stat: -rwxr-xr-x 717 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#! /usr/bin/lua

require 'Test.More'

if package.loaded['luacov'] then
    skip_all('coverage')
else
    plan 'no_plan'
end

local mp = require 'MessagePack'

local unpack = table.unpack or unpack
math.randomseed(os.time())
for _ = 1, 1000000 do
    local t = {}
    for i = 1, 128 do
        t[i] = math.random(0, 255)
    end
    local data = string.char(unpack(t))
    local r, msg = pcall(mp.unpack, data)
    if r == true then
        pass()
    else
        if     not msg:match'extra bytes$'
           and not msg:match'missing bytes$'
           and not msg:match'is unimplemented$' then
            diag(table.concat(t, ' '))
            diag(msg)
            fail()
        end
    end
end

done_testing()