Skip to content

Commit f2f17a7

Browse files
authored
fix(postgres): don't panic if M or C Notice fields are not UTF-8 (#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.
1 parent 83a7d14 commit f2f17a7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

sqlx-postgres/src/message/response.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,19 @@ impl Decode<'_> for Notice {
153153
}
154154

155155
b'M' => {
156+
_ = from_utf8(&buf[v.0 as usize..v.1 as usize])
157+
.map_err(|_| notice_protocol_err())?;
156158
message = v;
157159
}
158160

159161
b'C' => {
162+
_ = from_utf8(&buf[v.0 as usize..v.1 as usize])
163+
.map_err(|_| notice_protocol_err())?;
160164
code = v;
161165
}
162166

167+
// If more fields are added, make sure to check that they are valid UTF-8,
168+
// otherwise the get_cached_str method will panic.
163169
_ => {}
164170
}
165171
}

0 commit comments

Comments
 (0)