Skip to content

Commit 151813d

Browse files
authored
Validate pyexpat SetBase strings (#9581)
Reject embedded NULs and convert base strings to UTF-8 fallibly before storing them, instead of panicking on surrogates. Assisted-by: OpenAI Codex:model version not exposed
1 parent 0b081b0 commit 151813d

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎crates/stdlib/src/pyexpat.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,11 +1253,15 @@ mod _pyexpat {
12531253
}
12541254

12551255
#[pymethod(name = "SetBase")]
1256-
fn set_base(zelf: &Py<Self>, base: PyStrRef) {
1256+
fn set_base(zelf: &Py<Self>, base: PyUtf8StrRef, vm: &VirtualMachine) -> PyResult<()> {
1257+
if base.as_str().contains('\0') {
1258+
return Err(vm.new_value_error("embedded null character"));
1259+
}
12571260
// Store-only compatibility state for xml.sax locator APIs. The
12581261
// xml-rs backend still does not perform Expat-style base URI
12591262
// resolution for external entities.
1260-
*zelf.base.write() = Some(AsRef::<str>::as_ref(&base).to_owned());
1263+
*zelf.base.write() = Some(base.as_str().to_owned());
1264+
Ok(())
12611265
}
12621266

12631267
#[pymethod(name = "GetBase")]

0 commit comments

Comments
 (0)