summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2025-02-12 07:40:20 +0100
committerMitya Selivanov <automainint@guattari.tech>2025-02-12 07:40:20 +0100
commit8e76a23e425515ffd0e63b7db7a3caca058f6a70 (patch)
treee0509bfb77d063bb15ad1425531f692fd3d19889
parent2d71f1099f0eb3ef6e17316a520d3d710dec1ac0 (diff)
downloadreduced_system_layer-8e76a23e425515ffd0e63b7db7a3caca058f6a70.zip
Fix buffer overflow
-rwxr-xr-xreduced_system_layer.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/reduced_system_layer.c b/reduced_system_layer.c
index 3d6a08d..ab2b591 100755
--- a/reduced_system_layer.c
+++ b/reduced_system_layer.c
@@ -111,9 +111,6 @@
#/ - macOS support
#/ - Mobile devices support
#/
-#/ Bugs
-#/ - Buffer overflow after resizing the window.
-#/
#/ Done
#/
#/ - Examples
@@ -252,7 +249,7 @@ i32 main(i32 argc, c8 **argv);
#endif
#ifndef STATIC_MEMORY_BUFFER_SIZE
-#define STATIC_MEMORY_BUFFER_SIZE (20 * 1024 * 1024)
+#define STATIC_MEMORY_BUFFER_SIZE (40 * 1024 * 1024)
#endif
#ifndef MEMORY_CHUNK_SIZE
@@ -3383,17 +3380,27 @@ void render_main_window_frame(void) {
update_main_window_frame_();
+ i64 size = g_platform.frame_width * g_platform.frame_height;
+ if (size > g_platform.num_pixels)
+ size = g_platform.num_pixels;
+
if (g_platform.frame_width == _image.width && g_platform.frame_height == _image.height) {
- i64 size = g_platform.frame_width * g_platform.frame_height;
+ if (size > _pixels_internal_len)
+ size = _pixels_internal_len;
for (i64 i = 0; i < size; ++i)
_pixels_internal[i] = rgb_u32_from_f32_((vec3_f32) { g_platform.pixels[i].x, g_platform.pixels[i].y, g_platform.pixels[i].z });
} else {
- i64 size = g_platform.frame_width * g_platform.frame_height;
+ if (size > _pixels_scaled_len)
+ size = _pixels_scaled_len;
for (i64 i = 0; i < size; ++i)
_pixels_scaled[i] = rgb_u32_from_f32_((vec3_f32) { g_platform.pixels[i].x, g_platform.pixels[i].y, g_platform.pixels[i].z });
for (i64 j = 0; j < _image.height; ++j) {
+ if ((j + 1) * _image.width > _pixels_internal_len)
+ break;
i64 j0 = (j * g_platform.frame_height) / _image.height;
+ if ((j0 + 1) * g_platform.frame_width > _pixels_scaled_len)
+ break;
for (i64 i = 0; i < _image.width; ++i) {
i64 i0 = (i * g_platform.frame_width) / _image.width;
_pixels_internal[j * _image.width + i] = _pixels_scaled[j0 * g_platform.frame_width + i0];