rustc: Fail fast when compiling a source file larger than 4 GiB - 1 B
Fixes #132862
This commit is contained in:
parent
209799f3b9
commit
5caf516cd0
2 changed files with 15 additions and 1 deletions
|
@ -1843,6 +1843,8 @@ impl StableSourceFileId {
|
|||
}
|
||||
|
||||
impl SourceFile {
|
||||
const MAX_FILE_SIZE: u32 = u32::MAX - 1;
|
||||
|
||||
pub fn new(
|
||||
name: FileName,
|
||||
mut src: String,
|
||||
|
@ -1863,6 +1865,9 @@ impl SourceFile {
|
|||
let stable_id = StableSourceFileId::from_filename_in_current_crate(&name);
|
||||
let source_len = src.len();
|
||||
let source_len = u32::try_from(source_len).map_err(|_| OffsetOverflowError)?;
|
||||
if source_len > Self::MAX_FILE_SIZE {
|
||||
return Err(OffsetOverflowError);
|
||||
}
|
||||
|
||||
let (lines, multibyte_chars) = analyze_source_file::analyze_source_file(&src);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue