mirror of
https://github.com/nushell/nushell.git
synced 2025-08-26 20:09:00 +02:00
Fix panic in unit parsing with non-UTF8 code (#16355)
# Description Trying to parse non-UTF8 data as a value with unit (part of every literal parse) introduced a replacement character which shifted the span information so the indices where incorrect and triggered a panic. This has been resolved by removing a bad `String::from_utf8_lossy` # User-Facing Changes One less possible panic # Tests + Formatting Added a test with the original reproducer from fuzzing: File with `0\xffB` where the `\xff` represents the non utf-8 char `FF` run as a script to trigger
This commit is contained in:
committed by
GitHub
parent
61a89c1834
commit
3a82c6c88d
@@ -292,6 +292,21 @@ pub fn parse_filesize() {
|
||||
assert_eq!(value.unit.item, Unit::Filesize(FilesizeUnit::B));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn parse_non_utf8_fails() {
|
||||
let engine_state = EngineState::new();
|
||||
let mut working_set = StateWorkingSet::new(&engine_state);
|
||||
|
||||
// Panic when parsing units was triggered by non-UTF8 characters
|
||||
// due to bad handling via `String::from_utf8_lossy`
|
||||
//
|
||||
// See https://github.com/nushell/nushell/pull/16355
|
||||
let _block = parse(&mut working_set, None, b"0\xffB", true);
|
||||
|
||||
// Asserting on the exact error doesn't make as much sense as
|
||||
assert!(!working_set.parse_errors.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn parse_cell_path() {
|
||||
let engine_state = EngineState::new();
|
||||
|
Reference in New Issue
Block a user