diff --git a/src/lua/msgpack.c b/src/lua/msgpack.c
index 376e3bb151ba71d08699e1a58d9d092203258da0..acd860a9c9c97adc060cd35cb274dd7cd79d15dc 100644
--- a/src/lua/msgpack.c
+++ b/src/lua/msgpack.c
@@ -548,6 +548,9 @@ lua_ibuf_msgpack_decode(lua_State *L)
 {
 	uint32_t ctypeid = 0;
 	const char *rpos = *(const char **)luaL_checkcdata(L, 1, &ctypeid);
+	if (rpos == NULL) {
+		luaL_error(L, "msgpack.ibuf_decode: rpos is null");
+	}
 	struct luaL_serializer *cfg = luaL_checkserializer(L);
 	luamp_decode(L, cfg, &rpos);
 	*(const char **)luaL_pushcdata(L, ctypeid) = rpos;
diff --git a/test/app-tap/msgpack.test.lua b/test/app-tap/msgpack.test.lua
index d3e6da66f2f00554af78bd679e5a9600c5fe1e95..0e1692ad938c4f357ea873b9d8503442d8abde22 100755
--- a/test/app-tap/msgpack.test.lua
+++ b/test/app-tap/msgpack.test.lua
@@ -36,14 +36,17 @@ local function test_offsets(test, s)
 end
 
 local function test_misc(test, s)
-    test:plan(3)
+    test:plan(4)
     local ffi = require('ffi')
+    local buffer = require('buffer')
     local buf = ffi.cast("const char *", "\x91\x01")
     local bufcopy = ffi.cast('const char *', buf)
     local bufend, result = s.ibuf_decode(buf)
+    local st,e = pcall(s.ibuf_decode, buffer.ibuf().rpos)
     test:is(buf, bufcopy, "ibuf_decode argument is constant")
     test:is(buf + 2, bufend, 'ibuf_decode position')
     test:is_deeply(result, {1}, "ibuf_decode result")
+    test:ok(not st and e:match("null"), "null ibuf")
 end
 
 tap.test("msgpack", function(test)