[drivers][graphic] 拒绝非法帧缓冲偏移 (#11970)

在读写长度计算前拒绝负偏移和缓冲区外偏移。
This commit is contained in:
usualtreee authored and GitHub committed 2026-11-05 11:17:49 +08:00
1 parent b5de39d977
commit 3277e831bf
1 file changed
+10
+10
View File
@@ -176,6 +176,11 @@ static rt_ssize_t _graphic_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_
struct rt_graphic_device *gdev = raw_to_graphic(dev);
struct rt_graphic_plane *plane = gdev->primary_plane;
if (pos < 0 || (rt_size_t)pos >= plane->framebuffer_len)
{
return 0;
}
res = rt_min_t(rt_ssize_t, plane->framebuffer_len - pos, size);
if (res > 0)
@@ -196,6 +201,11 @@ static rt_ssize_t _graphic_write(rt_device_t dev, rt_off_t pos, const void *buff
struct rt_graphic_device *gdev = raw_to_graphic(dev);
struct rt_graphic_plane *plane = gdev->primary_plane;
if (pos < 0 || (rt_size_t)pos >= plane->framebuffer_len)
{
return 0;
}
res = rt_min_t(rt_ssize_t, plane->framebuffer_len - pos, size);
if (res > 0)