fix(postgres) use signed int for length prefix in PgCopyIn (#3701)

This commit is contained in:
joeydewaal 2025-01-24 23:30:02 +01:00 committed by GitHub
parent a83395a360
commit a408c490fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

2
Cargo.lock generated
View File

@ -3563,7 +3563,7 @@ version = "0.8.3"
dependencies = [
"async-io 1.13.0",
"async-std",
"base64 0.22.0",
"base64 0.22.1",
"bigdecimal",
"bit-vec",
"bstr",

View File

@ -230,10 +230,10 @@ impl<C: DerefMut<Target = PgConnection>> PgCopyIn<C> {
}
// Write the length
let read32 = u32::try_from(read)
.map_err(|_| err_protocol!("number of bytes read exceeds 2^32: {}", read))?;
let read32 = i32::try_from(read)
.map_err(|_| err_protocol!("number of bytes read exceeds 2^31 - 1: {}", read))?;
(&mut buf.get_mut()[1..]).put_u32(read32 + 4);
(&mut buf.get_mut()[1..]).put_i32(read32 + 4);
conn.inner.stream.flush().await?;
}