summaryrefslogtreecommitdiff
path: root/kms++util
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ti.com>2018-01-09 12:50:29 +0200
committerTomi Valkeinen <tomi.valkeinen@ti.com>2018-01-09 12:53:17 +0200
commit6ea6e0de706d98147c5382d6e2fb01751d327581 (patch)
tree52febfbf072c7bbe0fb48c4e0b87acc938d77b35 /kms++util
parenteafc32efc0a6292678f7542e36b78a433ad8770a (diff)
add safeguards to draw_*_pixel() to prevent memory corruption
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Diffstat (limited to 'kms++util')
-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
{
void draw_rgb_pixel(IFramebuffer& buf, unsigned x, unsigned y, RGB color)
{
+ if (x >= buf.width() || y >= buf.height())
+ throw runtime_error("attempt to draw outside the buffer");
+
switch (buf.format()) {
case PixelFormat::XRGB8888:
case PixelFormat::ARGB8888:
@@ -58,6 +61,9 @@ void draw_rgb_pixel(IFramebuffer& buf, unsigned x, unsigned y, RGB color)
void draw_yuv422_macropixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv1, YUV yuv2)
{
+ if ((x + 1) >= buf.width() || y >= buf.height())
+ throw runtime_error("attempt to draw outside the buffer");
+
ASSERT((x & 1) == 0);
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,
void draw_yuv420_macropixel(IFramebuffer& buf, unsigned x, unsigned y,
YUV yuv1, YUV yuv2, YUV yuv3, YUV yuv4)
{
+ if ((x + 1) >= buf.width() || (y + 1) >= buf.height())
+ throw runtime_error("attempt to draw outside the buffer");
+
ASSERT((x & 1) == 0);
ASSERT((y & 1) == 0);