Skip to content

Commit 164c6d5

Browse files
committed
Fixed optionalLength calculation...DOH!
1 parent f15dcfb commit 164c6d5

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/ws_dissector_helper.lua

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -259,32 +259,31 @@ function Field.COMPOSITE(fields)
259259
-- a COMPOSITE before parsing. So if a field is OPTIONAL, return two
260260
-- two lengths, the required and the optional (includes the
261261
-- required).
262-
local requiredLength = 0
263-
local optionalLength = 0
264-
for _, field in ipairs(fields) do
265-
if not field.optional then
266-
requiredLength = requiredLength + field:len()
262+
local requiredLen = 0
263+
local optionalLen = 0
264+
for _, field in ipairs(self.fields) do
265+
if field.optional then
266+
optionalLen = field:len()
267267
else
268-
optionalLength = requiredLength + field:len()
268+
requiredLen = requiredLen + field:len()
269269
end
270270
end
271-
return requiredLength, optionalLength
271+
return requiredLen, requiredLen + optionalLen
272272
end,
273273
value = function(self, tvb, off)
274274
wsdh:trace('Getting value of field ' .. self.name)
275275
-- Note that field_len is only the required fields. If there is an
276276
-- OPTIONAL field at the end of the COMPOSITE, it cannot be handled
277277
-- and the returned value will not include it.
278278
local fieldLen, optionalLen = self:len()
279-
if off + optionalLen<= tvb:len() then
279+
if off + optionalLen <= tvb:len() then
280280
fieldLen = optionalLen
281281
end
282-
283282
return tvb(off, fieldLen):string(), tvb(off, fieldLen)
284283
end,
285284
getOffset = function(self, abbr1)
286285
local offset = 0;
287-
for _, field in ipairs(fields) do
286+
for _, field in ipairs(self.fields) do
288287
if field.abbr == abbr1 then
289288
return offset
290289
else
@@ -302,7 +301,7 @@ function Field.COMPOSITE(fields)
302301
end
303302

304303
local addedBytes = 0
305-
for _, field in ipairs(fields) do
304+
for _, field in ipairs(self.fields) do
306305
local fieldLen = field:add_to(subTree, tvb, off + addedBytes)
307306
if fieldLen == 0 and not field.optional then
308307
return 0

0 commit comments

Comments
 (0)