mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Merge #7116
7116: Fix deep syntax tree bug generated by proc-macro r=jonas-schievink a=edwin0cheng This PR fixed a bug from `semver-parser` and `pest_derive` crates which generate a very deep syntax tree such that serde reject to de-serialize. To fix this bug, we disabled recursion limit in `serde` (by calling [`Deserializer::disable_recursion_limit`](https://docs.rs/serde_json/1.0.61/serde_json/struct.Deserializer.html#method.disable_recursion_limit)) I have a feeling that we still need some way to protect against bad proc-macro generating huge syntax node, but I have no idea right now. r? @jonas-schievink Fixes #7103 Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
This commit is contained in:
commit
51d29fe554
2 changed files with 11 additions and 4 deletions
|
@ -58,7 +58,13 @@ pub trait Message: Serialize + DeserializeOwned {
|
|||
fn read(inp: &mut impl BufRead) -> io::Result<Option<Self>> {
|
||||
Ok(match read_json(inp)? {
|
||||
None => None,
|
||||
Some(text) => Some(serde_json::from_str(&text)?),
|
||||
Some(text) => {
|
||||
let mut deserializer = serde_json::Deserializer::from_str(&text);
|
||||
// Note that some proc-macro generate very deep syntax tree
|
||||
// We have to disable the current limit of serde here
|
||||
deserializer.disable_recursion_limit();
|
||||
Some(Self::deserialize(&mut deserializer)?)
|
||||
}
|
||||
})
|
||||
}
|
||||
fn write(self, out: &mut impl Write) -> io::Result<()> {
|
||||
|
|
|
@ -92,10 +92,11 @@ fn client_loop(task_rx: Receiver<Task>, mut process: Process) {
|
|||
for Task { req, result_tx } in task_rx {
|
||||
match send_request(&mut stdin, &mut stdout, req) {
|
||||
Ok(res) => result_tx.send(res).unwrap(),
|
||||
Err(_err) => {
|
||||
Err(err) => {
|
||||
log::error!(
|
||||
"proc macro server crashed, server process state: {:?}",
|
||||
process.child.try_wait()
|
||||
"proc macro server crashed, server process state: {:?}, server request error: {:?}",
|
||||
process.child.try_wait(),
|
||||
err
|
||||
);
|
||||
let res = Response::Error(ResponseError {
|
||||
code: ErrorCode::ServerErrorEnd,
|
||||
|
|
Loading…
Reference in a new issue