# HG changeset patch # User Kim Alvefur # Date 1602526878 -7200 # Node ID 413bd21ba449993a6cfc797acb0d3fa60d3cf94d # Parent a8ef69f7fc35ff4d619d13de667340ef08f2afc8 net.websocket.frames: Read buffer length correctly in Lua 5.1 (fix #1598) COMPAT: The __len metamethod does not work with tables in Lua 5.1. Both strings and util.dbuffer now expose their length as a :len() method. diff -r a8ef69f7fc35 -r 413bd21ba449 net/websocket/frames.lua --- a/net/websocket/frames.lua Mon Oct 12 20:20:02 2020 +0200 +++ b/net/websocket/frames.lua Mon Oct 12 20:21:18 2020 +0200 @@ -76,7 +76,7 @@ end local function parse_frame_header(frame) - if #frame < 2 then return; end + if frame:len() < 2 then return; end local byte1, byte2 = frame:byte(1, 2); local result = { @@ -98,7 +98,7 @@ end local header_length = 2 + length_bytes + (result.MASK and 4 or 0); - if #frame < header_length then return; end + if frame:len() < header_length then return; end if length_bytes == 2 then result.length = read_uint16be(frame, 3); @@ -141,7 +141,7 @@ local function parse_frame(frame) local result, pos = parse_frame_header(frame); - if result == nil or #frame < (pos + result.length) then return nil, nil, result; end + if result == nil or frame:len() < (pos + result.length) then return nil, nil, result; end result.data = parse_frame_body(frame, result, pos+1); return result, pos + result.length; end