[PR #1816] [MERGED] fix(rust): Add null checks and handle invalid UTF-8 in FFI functions #2562

Closed
opened 2026-01-29 17:22:47 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/CCExtractor/ccextractor/pull/1816
Author: @cfsmp3
Created: 12/14/2025
Status: Merged
Merged: 12/14/2025
Merged by: @cfsmp3

Base: masterHead: fix/ffi-null-checks-and-panics


📝 Commits (1)

  • 6ad0d9a fix(rust): Add null checks and handle invalid UTF-8 in FFI functions

📊 Changes

1 file changed (+19 additions, -7 deletions)

View changed files

📝 src/rust/src/lib.rs (+19 -7)

📄 Description

Summary

  • Add null pointer checks in Rust FFI functions to prevent crashes when called with invalid arguments from C code
  • Replace panic-prone expect() with graceful to_string_lossy() for handling invalid UTF-8

Changes

ccxr_process_cc_data (MEDIUM severity)

  • Added null check for dec_ctx pointer
  • Added null check for data pointer
  • Added bounds check for cc_count > 0
  • Added null check for dec_ctx.dtvcc before dereferencing

ccxr_parse_parameters (LOW severity)

  • Added null check for argv pointer
  • Added bounds check for argc > 0
  • Replaced to_str().expect() with to_string_lossy() to handle invalid UTF-8 gracefully without panicking

Test plan

  • Cargo clippy passes
  • Full build completes successfully
  • Run test suite to verify no regressions

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/CCExtractor/ccextractor/pull/1816 **Author:** [@cfsmp3](https://github.com/cfsmp3) **Created:** 12/14/2025 **Status:** ✅ Merged **Merged:** 12/14/2025 **Merged by:** [@cfsmp3](https://github.com/cfsmp3) **Base:** `master` ← **Head:** `fix/ffi-null-checks-and-panics` --- ### 📝 Commits (1) - [`6ad0d9a`](https://github.com/CCExtractor/ccextractor/commit/6ad0d9a319c7c2aa73b129d8bac4e25a52fb08ff) fix(rust): Add null checks and handle invalid UTF-8 in FFI functions ### 📊 Changes **1 file changed** (+19 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `src/rust/src/lib.rs` (+19 -7) </details> ### 📄 Description ## Summary - Add null pointer checks in Rust FFI functions to prevent crashes when called with invalid arguments from C code - Replace panic-prone `expect()` with graceful `to_string_lossy()` for handling invalid UTF-8 ## Changes ### `ccxr_process_cc_data` (MEDIUM severity) - Added null check for `dec_ctx` pointer - Added null check for `data` pointer - Added bounds check for `cc_count > 0` - Added null check for `dec_ctx.dtvcc` before dereferencing ### `ccxr_parse_parameters` (LOW severity) - Added null check for `argv` pointer - Added bounds check for `argc > 0` - Replaced `to_str().expect()` with `to_string_lossy()` to handle invalid UTF-8 gracefully without panicking ## Test plan - [x] Cargo clippy passes - [x] Full build completes successfully - [ ] Run test suite to verify no regressions 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 17:22:47 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2562