Skip to content

Commit 2cb6217

Browse files
committed
fix: audit sqlx_postgres::types::array for bad casts
1 parent 8a17e46 commit 2cb6217

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

sqlx-postgres/src/types/array.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,14 @@ where
174174
}
175175
}
176176

177-
buf.extend(&(self.len() as i32).to_be_bytes()); // len
177+
let array_len = i32::try_from(self.len()).map_err(|_| {
178+
format!(
179+
"encoded array length is too large for Postgres: {}",
180+
self.len()
181+
)
182+
})?;
183+
184+
buf.extend(array_len.to_be_bytes()); // len
178185
buf.extend(&1_i32.to_be_bytes()); // lower bound
179186

180187
for element in self.iter() {

0 commit comments

Comments
 (0)