Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
libvncserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rasky
libvncserver
Commits
8220f4da
Commit
8220f4da
authored
Oct 06, 2014
by
newsoft
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure that no integer overflow could occur during scaling
parent
9aa9ac59
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
1 deletion
+22
-1
scale.c
libvncserver/scale.c
+22
-1
No files found.
libvncserver/scale.c
View file @
8220f4da
...
...
@@ -66,6 +66,12 @@
(double) ((int) (x)) : (double) ((int) (x) + 1) )
#define FLOOR(x) ( (double) ((int) (x)) )
static
inline
int
pad4
(
int
value
)
{
int
remainder
=
value
&
3
;
if
(
!
remainder
)
return
value
;
return
value
+
4
-
remainder
;
}
int
ScaleX
(
rfbScreenInfoPtr
from
,
rfbScreenInfoPtr
to
,
int
x
)
{
...
...
@@ -281,14 +287,29 @@ rfbScreenInfoPtr rfbScaledScreenAllocate(rfbClientPtr cl, int width, int height)
ptr
=
malloc
(
sizeof
(
rfbScreenInfo
));
if
(
ptr
!=
NULL
)
{
int
allocSize
;
/* copy *everything* (we don't use most of it, but just in case) */
memcpy
(
ptr
,
cl
->
screen
,
sizeof
(
rfbScreenInfo
));
/* SECURITY: make sure that no integer overflow will occur afterwards.
* Note: this is defensive coding, as the check should have already been
* performed during initial, non-scaled screen setup.
*/
allocSize
=
pad4
(
width
*
(
ptr
->
bitsPerPixel
/
8
));
/* per protocol, width<2**16 and bpp<256 */
if
(
height
==
0
||
allocSize
>=
SIZE_MAX
/
height
)
{
free
(
ptr
);
return
NULL
;
/* malloc() will allocate an incorrect buffer size - early abort */
}
/* Resume copy everything */
ptr
->
width
=
width
;
ptr
->
height
=
height
;
ptr
->
paddedWidthInBytes
=
(
ptr
->
bitsPerPixel
/
8
)
*
ptr
->
width
;
/* Need to by multiples of 4 for Sparc systems */
ptr
->
paddedWidthInBytes
+=
(
ptr
->
paddedWidthInBytes
%
4
);
ptr
->
paddedWidthInBytes
=
pad4
(
ptr
->
paddedWidthInBytes
);
/* Reset the reference count to 0! */
ptr
->
scaledScreenRefCount
=
0
;
...
...
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