aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomi Valkeinen2018-01-09 04:50:29 -0600
committerTomi Valkeinen2018-01-09 04:53:17 -0600
commit6ea6e0de706d98147c5382d6e2fb01751d327581 (patch)
tree52febfbf072c7bbe0fb48c4e0b87acc938d77b35
parenteafc32efc0a6292678f7542e36b78a433ad8770a (diff)
downloadexternal-libkmsxx-6ea6e0de706d98147c5382d6e2fb01751d327581.tar.gz
external-libkmsxx-6ea6e0de706d98147c5382d6e2fb01751d327581.tar.xz
external-libkmsxx-6ea6e0de706d98147c5382d6e2fb01751d327581.zip
add safeguards to draw_*_pixel() to prevent memory corruption
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
-rw-r--r--kms++util/src/drawing.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/kms++util/src/drawing.cpp b/kms++util/src/drawing.cpp
index a187dc0..4e5c6c1 100644
--- a/kms++util/src/drawing.cpp
+++ b/kms++util/src/drawing.cpp
@@ -8,6 +8,9 @@ namespace kms
8{ 8{
9void draw_rgb_pixel(IFramebuffer& buf, unsigned x, unsigned y, RGB color) 9void draw_rgb_pixel(IFramebuffer& buf, unsigned x, unsigned y, RGB color)
10{ 10{
11 if (x >= buf.width() || y >= buf.height())
12 throw runtime_error("attempt to draw outside the buffer");
13
11 switch (buf.format()) { 14 switch (buf.format()) {
12 case PixelFormat::XRGB8888: 15 case PixelFormat::XRGB8888:
13 case PixelFormat::ARGB8888: 16 case PixelFormat::ARGB8888:
@@ -58,6 +61,9 @@ void draw_rgb_pixel(IFramebuffer& buf, unsigned x, unsigned y, RGB color)
58 61
59void draw_yuv422_macropixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv1, YUV yuv2) 62void draw_yuv422_macropixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv1, YUV yuv2)
60{ 63{
64 if ((x + 1) >= buf.width() || y >= buf.height())
65 throw runtime_error("attempt to draw outside the buffer");
66
61 ASSERT((x & 1) == 0); 67 ASSERT((x & 1) == 0);
62 68
63 uint8_t *p = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x * 2); 69 uint8_t *p = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
@@ -104,6 +110,9 @@ void draw_yuv422_macropixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv1,
104void draw_yuv420_macropixel(IFramebuffer& buf, unsigned x, unsigned y, 110void draw_yuv420_macropixel(IFramebuffer& buf, unsigned x, unsigned y,
105 YUV yuv1, YUV yuv2, YUV yuv3, YUV yuv4) 111 YUV yuv1, YUV yuv2, YUV yuv3, YUV yuv4)
106{ 112{
113 if ((x + 1) >= buf.width() || (y + 1) >= buf.height())
114 throw runtime_error("attempt to draw outside the buffer");
115
107 ASSERT((x & 1) == 0); 116 ASSERT((x & 1) == 0);
108 ASSERT((y & 1) == 0); 117 ASSERT((y & 1) == 0);
109 118