From a408c490fdf7afbd7b0f1869ef5265b4c00ba43f Mon Sep 17 00:00:00 2001 From: joeydewaal <99046430+joeydewaal@users.noreply.github.com> Date: Fri, 24 Jan 2025 23:30:02 +0100 Subject: [PATCH] fix(postgres) use signed int for length prefix in `PgCopyIn` (#3701) --- Cargo.lock | 2 +- sqlx-postgres/src/copy.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 58162ba6..c1128994 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/sqlx-postgres/src/copy.rs b/sqlx-postgres/src/copy.rs index ddc187e9..fd9ed7e8 100644 --- a/sqlx-postgres/src/copy.rs +++ b/sqlx-postgres/src/copy.rs @@ -230,10 +230,10 @@ impl> PgCopyIn { } // 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?; }