Skip to content

Commit

Permalink
fix(postgres): don't panic if M or C Notice fields are not UTF-8 (l…
Browse files Browse the repository at this point in the history
…aunchbadge#3346)

* fix(postgres): don't panic if `M` or `C` Notice fields are not UTF-8

This has been observed with an old version of PostgreSQL (11.0.4)
running on Windows Server 2016 with windows-1252 encoding and French
locale.

This change replaces invalid UTF-8 fields with a default string, so the
other fields can still be read if they are valid.

* Revert "fix(postgres): don't panic if `M` or `C` Notice fields are not UTF-8"

This reverts commit 362ca98.

* Check that Notice M and C fields are valid UTF-8

Otherwise, we return the invalid UTF-8 error to avoid panicking later.
  • Loading branch information
YgorSouza authored and jrasanen committed Oct 14, 2024
1 parent 0a66ee9 commit fb50926
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sqlx-postgres/src/message/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,19 @@ impl Decode<'_> for Notice {
}

b'M' => {
_ = from_utf8(&buf[v.0 as usize..v.1 as usize])
.map_err(|_| notice_protocol_err())?;
message = v;
}

b'C' => {
_ = from_utf8(&buf[v.0 as usize..v.1 as usize])
.map_err(|_| notice_protocol_err())?;
code = v;
}

// If more fields are added, make sure to check that they are valid UTF-8,
// otherwise the get_cached_str method will panic.
_ => {}
}
}
Expand Down

0 comments on commit fb50926

Please sign in to comment.