Skip to content

Commit e2e9288

Browse files
authored
Merge pull request #14600 from rabbitmq/mergify/bp/v4.1.x/pr-14599
CQ shared: Fix off-by-nine error leading to lost messages (backport #14576) (backport #14599)
2 parents c2bb0d6 + d399f0c commit e2e9288

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

deps/rabbit/src/rabbit_msg_store.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,7 @@ scan_data(<<Size:64, MsgIdInt:128, _Rest/bits>> = Data, Fd, Fun, Offset, FileSiz
15991599
end;
16001600
%% This might be the start of a message.
16011601
scan_data(<<Size:64, Rest/bits>> = Data, Fd, Fun, Offset, FileSize, MsgIdsFound, Acc)
1602-
when byte_size(Rest) < Size + 1, Size < FileSize - Offset ->
1602+
when byte_size(Rest) < Size + 1, Size + 9 =< FileSize - Offset ->
16031603
scan(Data, Fd, Fun, Offset, FileSize, MsgIdsFound, Acc);
16041604
scan_data(Data, Fd, Fun, Offset, FileSize, MsgIdsFound, Acc)
16051605
when byte_size(Data) < 8 ->

deps/rabbit/test/backing_queue_SUITE.erl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,17 @@ msg_store_file_scan1(Config) ->
710710
[{bin, <<0, 0:48, 17, 17, "idididididididid", 255, 0:4352/unit:8, 255>>}],
711711
{ok, [{<<"idididididididid">>, 4378, 1}]},
712712
fun(Obj = {<<"idididididididid">>, 4378, 1}) -> {valid, Obj}; (_) -> invalid end),
713+
%% Off-by-nine regression testing. The file scanning could miss
714+
%% some messages if previous data looked like a message but its
715+
%% size went past the end of the file.
716+
lists:foreach(fun(N) ->
717+
ok = Scan([
718+
{bin, <<(4194304 + N):64, 0:(4194304 - 8 - 25 - 10)/unit:8>>},
719+
{msg, gen_id(), <<>>},
720+
%% Padding ensures there's no 255 at the end of the size indicated by 'bin'.
721+
{pad, 10}
722+
])
723+
end, lists:seq(-9, -1)),
713724
%% All good!!
714725
passed.
715726

0 commit comments

Comments
 (0)