diff options
Diffstat (limited to 'compiler/rustc_span/src/lib.rs')
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 5 | 
1 files changed, 5 insertions, 0 deletions
| diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 8966cfc9171..1481e1cbd91 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -1829,6 +1829,8 @@ impl StableSourceFileId { } impl SourceFile { + const MAX_FILE_SIZE: u32 = u32::MAX - 1; + pub fn new( name: FileName, mut src: String, @@ -1849,6 +1851,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); | 
