aboutsummaryrefslogtreecommitdiffstats
path: root/src/files_map.adb
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2017-11-13 06:08:55 +0100
committerTristan Gingold <tgingold@free.fr>2017-11-13 06:08:55 +0100
commit8313646e4f770b90e62eab238e5a0a0c4425262e (patch)
treeed610b94b48987d08043f181f8b54d75cae9f5f7 /src/files_map.adb
parentc3c170921c0b4fb4e01f2079fcd8bbb637a48459 (diff)
downloadghdl-8313646e4f770b90e62eab238e5a0a0c4425262e.tar.gz
ghdl-8313646e4f770b90e62eab238e5a0a0c4425262e.tar.bz2
ghdl-8313646e4f770b90e62eab238e5a0a0c4425262e.zip
files_map.adb: check for too large file.
Improve output of #456
Diffstat (limited to 'src/files_map.adb')
-rw-r--r--src/files_map.adb21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/files_map.adb b/src/files_map.adb
index 7d7676c81..b7cc795a1 100644
--- a/src/files_map.adb
+++ b/src/files_map.adb
@@ -797,10 +797,12 @@ package body Files_Map is
use GNAT.OS_Lib;
Fd : File_Descriptor;
- Res: Source_File_Entry;
+ Res : Source_File_Entry;
- Length: Source_Ptr;
- Buffer: File_Buffer_Acc;
+ Raw_Length : Long_Integer;
+ Length : Source_Ptr;
+
+ Buffer : File_Buffer_Acc;
begin
-- If the file is already loaded, nothing to do!
Res := Find_Source_File (Directory, Name);
@@ -822,9 +824,20 @@ package body Files_Map is
end if;
end;
+ Raw_Length := File_Length (Fd);
+
+ -- Check for too large files. Use 'Pos (ie universal integer) to avoid
+ -- errors in conversions.
+ if Long_Integer'Pos (Raw_Length) > Source_Ptr'Pos (Source_Ptr'Last)
+ or else Long_Integer'Pos (Raw_Length) > Integer'Pos (Integer'Last)
+ then
+ Close (Fd);
+ return No_Source_File_Entry;
+ end if;
+
Res := Create_Source_File_Entry (Directory, Name);
- Length := Source_Ptr (File_Length (Fd));
+ Length := Source_Ptr (Raw_Length);
Buffer :=
new File_Buffer (Source_Ptr_Org .. Source_Ptr_Org + Length + 1);