Skip to content

Commit ae152ab

Browse files
committed
fix the issue where sending multiple chunks with an excessive number of tags is not processed correctly
1 parent cbb753d commit ae152ab

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

mono/src/git_protocol/http.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,23 @@ pub async fn git_receive_pack(
194194
let mut data_stream = req.into_body().into_data_stream();
195195
let mut report_status = Bytes::new();
196196

197+
let mut chunk_buffer = BytesMut::new(); // Used to cache the data of chunks before the PACK subsequence is found.
197198
// Process the data stream to handle the Git receive-pack protocol.
198199
while let Some(chunk) = data_stream.next().await {
199200
let chunk = chunk.unwrap();
200201
// Process the data up to the "PACK" subsequence.
201202
if let Some(pos) = search_subsequence(&chunk, b"PACK") {
202-
pack_protocol.git_receive_pack_protocol(Bytes::copy_from_slice(&chunk[0..pos]));
203+
chunk_buffer.extend_from_slice(&chunk[0..pos]);
204+
pack_protocol.git_receive_pack_protocol(Bytes::copy_from_slice(&chunk_buffer));
203205
// Create a new stream from the remaining bytes and the rest of the data stream.
204-
let remaining_bytes = Bytes::copy_from_slice(&chunk[pos..]);
205-
let remaining_stream = stream::once(async { Ok(remaining_bytes) }).chain(data_stream);
206+
let left_chunk_bytes = Bytes::copy_from_slice(&chunk[pos..]);
207+
let pack_stream = stream::once(async { Ok(left_chunk_bytes) }).chain(data_stream);
206208
report_status = pack_protocol
207-
.git_receive_pack_stream(Box::pin(remaining_stream))
209+
.git_receive_pack_stream(Box::pin(pack_stream))
208210
.await?;
209211
break;
212+
} else {
213+
chunk_buffer.extend_from_slice(&chunk);
210214
}
211215
}
212216
tracing::info!("report status:{:?}", report_status);

0 commit comments

Comments
 (0)