This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -1843,6 +1843,8 @@ impl StableSourceFileId {
18431843}
18441844
18451845impl SourceFile {
1846+ const MAX_FILE_SIZE : u32 = u32:: MAX - 1 ;
1847+
18461848 pub fn new (
18471849 name : FileName ,
18481850 mut src : String ,
@@ -1863,6 +1865,9 @@ impl SourceFile {
18631865 let stable_id = StableSourceFileId :: from_filename_in_current_crate ( & name) ;
18641866 let source_len = src. len ( ) ;
18651867 let source_len = u32:: try_from ( source_len) . map_err ( |_| OffsetOverflowError ) ?;
1868+ if source_len > Self :: MAX_FILE_SIZE {
1869+ return Err ( OffsetOverflowError ) ;
1870+ }
18661871
18671872 let ( lines, multibyte_chars) = analyze_source_file:: analyze_source_file ( & src) ;
18681873
Original file line number Diff line number Diff line change @@ -115,6 +115,12 @@ impl FileLoader for RealFileLoader {
115115 }
116116
117117 fn read_file ( & self , path : & Path ) -> io:: Result < String > {
118+ if path. metadata ( ) . is_ok_and ( |metadata| metadata. len ( ) > SourceFile :: MAX_FILE_SIZE . into ( ) ) {
119+ return Err ( io:: Error :: other ( format ! (
120+ "text files larger than {} bytes are unsupported" ,
121+ SourceFile :: MAX_FILE_SIZE
122+ ) ) ) ;
123+ }
118124 fs:: read_to_string ( path)
119125 }
120126
@@ -297,7 +303,10 @@ impl SourceMap {
297303 /// unmodified.
298304 pub fn new_source_file ( & self , filename : FileName , src : String ) -> Lrc < SourceFile > {
299305 self . try_new_source_file ( filename, src) . unwrap_or_else ( |OffsetOverflowError | {
300- eprintln ! ( "fatal error: rustc does not support files larger than 4GB" ) ;
306+ eprintln ! (
307+ "fatal error: rustc does not support text files larger than {} bytes" ,
308+ SourceFile :: MAX_FILE_SIZE
309+ ) ;
301310 crate :: fatal_error:: FatalError . raise ( )
302311 } )
303312 }
You can’t perform that action at this time.
0 commit comments