NetrexMC / RakNet

RakNet implementation in Rust
Apache License 2.0
44 stars 12 forks source link

[BUG] The collect function in FragmentQueue fails to sort frames correctly. #55

Closed YouZiSoftware closed 7 months ago

YouZiSoftware commented 7 months ago

Describe the bug The sort_by function in the collect method of FragmentQueue is using id for comparison during sorting (it should actually be index), causing the Frame to be sorted incorrectly. As a result, in some instances, the output Vec<u8> may be incorrect.

To Reproduce Steps to reproduce the behavior: This issue may probabilistically occur when receiving a Fragment because the sorting is not done correctly, primarily due to the improper use of id instead of index in the sorting process.

Expected behavior Correcting the usage of the sort_by function, here is the suggested modified code:

frames.sort_by(|a, b| {
                    a.fragment_meta
                        .as_ref()
                        .unwrap()
                        .index
                        .cmp(&b.fragment_meta.as_ref().unwrap().index)
                });

Server versions (please complete the following information):

Additional context Here is the debug output of my code, and the buffer concatenation is not correct: code:

for frame in frames.iter() {
                    let fm = frame.fragment_meta.clone().unwrap();
                    println!("index: {}, len: {}", fm.index, frame.body.len());
                    buffer.extend_from_slice(&frame.body);
                }

output:

index: 0, len: 1463
index: 1, len: 1463
index: 5, len: 637
index: 2, len: 1463
index: 3, len: 1463
index: 4, len: 1463
john-bv commented 7 months ago

Do you have a input buffer source or no? If not, judging the frame length and indices im assuming this is a MC buffer source.

john-bv commented 7 months ago

This issue should be fixed! Please let me know if you're still having this issue after updating to 0.3.2!