Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/sql/mysql/protocol/HandshakeV10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,13 @@ impl HandshakeV10 {
);

// Length of auth plugin data
let mut auth_plugin_data_len = reader.int::<u8>()?;
if auth_plugin_data_len < 21 {
auth_plugin_data_len = 21;
}
let auth_plugin_data_len = reader.int::<u8>()?.max(21);

// Skip reserved bytes
reader.skip(10);

// Auth plugin data part 2
let remaining_auth_len = (auth_plugin_data_len - 8).max(13);
let remaining_auth_len = auth_plugin_data_len - 8;
let auth_data_2 = reader.read(remaining_auth_len as usize)?;
self.auth_plugin_data_part_2 = Box::<[u8]>::from(auth_data_2.slice());

Expand Down
1 change: 0 additions & 1 deletion src/sql/mysql/protocol/PreparedStatement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ impl<'a> Execute<'a> {
let mut null_bitmap_buf = [0u8; MYSQL_MAX_PARAMS];
let bitmap_bytes = self.params.len.div_ceil(8);
let null_bitmap = &mut null_bitmap_buf[0..bitmap_bytes];
null_bitmap.fill(0);

for i in 0..self.params.len {
if (self.params.is_null)(self.params.ctx, i) {
Expand Down
6 changes: 3 additions & 3 deletions src/sql/postgres/CommandTag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ impl<'a> CommandTag<'a> {
let number: u64 = 'brk: {
match cmd {
KnownCommand::Insert => {
let mut remaining = &tag[(first_space_index + 1).min(tag.len())..];
let mut remaining = &tag[first_space_index + 1..];
let Some(second_space) = strings::index_of_char(remaining, b' ') else {
return CommandTag::Other(tag);
};
let second_space = second_space as usize;
remaining = &remaining[(second_space + 1).min(remaining.len())..];
remaining = &remaining[second_space + 1..];
// Postgres wire is pure base-10 ASCII so radix-0/`_`/sign
// widening is unreachable.
match bun_core::fmt::parse_int::<u64>(remaining, 0) {
Expand All @@ -103,7 +103,7 @@ impl<'a> CommandTag<'a> {
}
}
_ => {
let after_tag = &tag[(first_space_index + 1).min(tag.len())..];
let after_tag = &tag[first_space_index + 1..];
match bun_core::fmt::parse_int::<u64>(after_tag, 0) {
Ok(n) => break 'brk n,
Err(err) => {
Expand Down
9 changes: 4 additions & 5 deletions src/sql/postgres/protocol/NewReader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ pub trait ReaderContext {
fn peek(&self) -> &[u8];
fn skip(&mut self, count: usize);
fn ensure_length(&mut self, count: usize) -> bool;
/// On `Ok`, the returned slice is exactly `count` bytes; otherwise
/// `Err(ShortRead)`. Callers rely on this: `int<Int>()` passes the
/// result straight to `from_be_slice` without re-checking length.
fn read(&mut self, count: usize) -> Result<Data, AnyPostgresError>;
fn read_z(&mut self) -> Result<Data, AnyPostgresError>;
}
Expand Down Expand Up @@ -126,11 +129,7 @@ impl<Context: ReaderContext> NewReaderWrap<Context> {

pub fn int<Int: ProtocolInt>(&mut self) -> Result<Int, AnyPostgresError> {
let data = self.read(Int::SIZE)?;
let slice = data.slice();
if slice.len() < Int::SIZE {
return Err(AnyPostgresError::ShortRead);
}
Ok(Int::from_be_slice(&slice[0..Int::SIZE]))
Ok(Int::from_be_slice(data.slice()))
}

pub fn peek_int<Int: ProtocolInt>(&self) -> Option<Int> {
Expand Down
Loading