Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
emacs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
emacs
emacs
Commits
2a47c44d
Commit
2a47c44d
authored
Apr 02, 2011
by
Paul Eggert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* fileio.c (Finsert_file_contents): Avoid signed integer overflow.
parent
a37c69bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
15 deletions
+12
-15
src/ChangeLog
src/ChangeLog
+2
-0
src/fileio.c
src/fileio.c
+10
-15
No files found.
src/ChangeLog
View file @
2a47c44d
2011-04-02 Paul Eggert <eggert@cs.ucla.edu>
* fileio.c (Finsert_file_contents): Avoid signed integer overflow.
* minibuf.c (read_minibuf_noninteractive): Use size_t for sizes.
Check for integer overflow on size calculations.
src/fileio.c
View file @
2a47c44d
...
...
@@ -3239,9 +3239,16 @@ variable `last-coding-system-used' to the coding system actually used. */)
record_unwind_protect
(
close_file_unwind
,
make_number
(
fd
));
/* Can happen on any platform that uses long as type of off_t, but allows
file sizes to exceed 2Gb, so give a suitable message. */
if
(
!
not_regular
&&
st
.
st_size
<
0
)
/* Arithmetic overflow can occur if an Emacs integer cannot represent the
file size, or if the calculations below overflow. The calculations below
double the file size twice, so check that it can be multiplied by 4
safely.
Also check whether the size is negative, which can happen on a platform
that allows file sizes greater than the maximum off_t value. */
if
(
!
not_regular
&&
!
(
0
<=
st
.
st_size
&&
st
.
st_size
<=
MOST_POSITIVE_FIXNUM
/
4
))
error
(
"Maximum buffer size exceeded"
);
/* Prevent redisplay optimizations. */
...
...
@@ -3268,18 +3275,6 @@ variable `last-coding-system-used' to the coding system actually used. */)
{
XSETINT
(
end
,
st
.
st_size
);
/* Arithmetic overflow can occur if an Emacs integer cannot
represent the file size, or if the calculations below
overflow. The calculations below double the file size
twice, so check that it can be multiplied by 4 safely. */
if
(
XINT
(
end
)
!=
st
.
st_size
/* Actually, it should test either INT_MAX or LONG_MAX
depending on which one is used for EMACS_INT. But in
any case, in practice, this test is redundant with the
one above.
|| st.st_size > INT_MAX / 4 */
)
error
(
"Maximum buffer size exceeded"
);
/* The file size returned from stat may be zero, but data
may be readable nonetheless, for example when this is a
file in the /proc filesystem. */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment