Skip to content

fix: add error handling and validation#1

Open
amnonbc wants to merge 1 commit into
mainfrom
fix/error-handling-and-validation
Open

fix: add error handling and validation#1
amnonbc wants to merge 1 commit into
mainfrom
fix/error-handling-and-validation

Conversation

@amnonbc
Copy link
Copy Markdown
Owner

@amnonbc amnonbc commented May 21, 2026

Summary

This PR addresses critical bugs and improves error handling and data validation across the DRM and framebuffer backends.

Changes

Critical Bug Fixes:

  • drm.Flip(): Now properly handles ioctl errors. Previously, errors were silently ignored, causing the active buffer pointer to be updated even when the hardware flip failed, leading to subsequent frames rendering to the wrong buffer.
  • drm.Open(): Standardized error cleanup paths to consistently use the cleanup function instead of scattered f.Close() calls, ensuring all resources are properly released.

Data Safety Improvements:

  • fb.Blit() and fb.Flip(): Added bounds validation to catch image size mismatches before blitting. Provides clear error logging when callers pass incorrectly-sized images.
  • fb.Open(): Added integer overflow protection when calculating framebuffer size. Added sanity check to reject unreasonably large allocations (>256MB).

Readability Enhancements:

  • Added detailed comments explaining Bayer matrix indexing (y&3, x&3) in blitToHardware()
  • Improved documentation for setPlaneRotation() about failure modes

Testing

All changes are backward compatible. The validation checks will catch invalid inputs that would have previously caused panics or undefined behavior.

Issues Addressed

  • Fixes potential data corruption in DRM backend when flip operations fail
  • Prevents undersized image buffers from causing memory access violations
  • Protects against integer overflow in framebuffer size calculation

- Fix critical bug in drm.Flip(): handle ioctl errors and don't swap buffers on failure
- Add bounds validation in fb.Blit() and fb.Flip() to catch image size mismatches
- Add integer overflow protection in fb.Open() for framebuffer size calculation
- Use consistent cleanup function in drm.Open() for all error paths
- Improve documentation for Bayer matrix indexing in blitToHardware()
- Add documentation to setPlaneRotation() about rotation failure handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant