Skip to content

Fix: Code vulnerabilities and unsafe practices #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Sambit003
Copy link

@Sambit003 Sambit003 commented Aug 6, 2025

Type of Change

  • New Feature
  • Bug Fix
  • Documentation
  • Performance Improvement
  • Test/CI
  • Refactor
  • Other:

Related Issues

Summary of Changes

This pull request introduces a series of safety and validation improvements across several modules, focusing on robust error handling for integer overflows, resource exhaustion, and port validation. The changes are grouped into three main themes: erasure coding arithmetic safety, time/resource exhaustion protection, and port validation in service management.

Arithmetic Safety and Error Handling in Erasure Coding:

  • Comprehensive use of checked arithmetic (checked_add, checked_sub, checked_mul) and error propagation in Erasure and ShardReader implementations to prevent integer overflows during size calculations, block offsets, and data writes. All critical arithmetic operations now return explicit errors or safe defaults on overflow, improving reliability and maintainability. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15]

Protection Against Resource Exhaustion and Unbounded Loops:

  • Added maximum iteration and time jump limits in LastMinuteLatency to prevent resource exhaustion and unbounded loops, including a new safe version of get_total that returns errors if time jumps are excessive.
  • Ensured histogram tagging in LastMinuteHistogram does not exceed bounds by clamping the tag index.

Port Validation and Error Messaging in Service Management:

  • Refactored port extraction and validation in ServiceManager to include explicit range checks, reserved port warnings, and unified parsing/validation logic. Service start and restart methods now validate ports before proceeding, with improved error messaging. [1] [2] [3] [4]

Refactoring for Code Safety
Replaced unsafe AtomicPtr usage with the safer Arc<RwLock> primitive for concurrent state management in both the QueryStateMachine and the metadata Cache. This improves memory safety and reduces the risk of race conditions.
These changes collectively enhance the system's robustness against common runtime errors and improve operational safety.

Checklist

  • I have read and followed the CONTRIBUTING.md guidelines
  • Code is formatted with cargo fmt --all
  • Passed cargo clippy --all-targets --all-features -- -D warnings
  • Passed cargo check --all-targets
  • Added/updated necessary tests
  • Documentation updated (if needed)
  • CI/CD passed (if applicable)

Impact

  • Breaking change (compatibility)
  • Requires doc/config/deployment update
  • Other impact:

Additional Notes


Thank you for your contribution! Please ensure your PR follows the community standards (CODE_OF_CONDUCT.md) and sign the CLA if this is your first contribution.

@CLAassistant
Copy link

CLAassistant commented Aug 6, 2025

CLA assistant check
All committers have signed the CLA.

@Sambit003
Copy link
Author

IDK why the e2e-test is failing, locally all the tests have passed. May be some kind of initialization issues in the CI/CD workflow. Please check on that and let me know.
@loverustfs

@loverustfs
Copy link
Contributor

@Sambit003

It looks like the unit test failed.


Backtrace:
  2025-08-07T01:42:46.837516Z  INFO s3s_test::runner: Test case end, summary: FnSummary { result: Err("Failed: service error"), duration_ns: 2809447, duration_ms: 2.809447 }
    at crates/s3s-test/src/runner.rs:177
    in s3s_test::runner::run_case with name: "test_assume_role"
    in s3s_test::runner::run_fixture with name: "STS"
    in s3s_test::runner::run_suite with name: "Advanced"

  2025-08-07T01:42:46.837532Z  INFO s3s_test::runner: Test fixture teardown
    at crates/s3s-test/src/runner.rs:149
    in s3s_test::runner::run_fixture with name: "STS"
    in s3s_test::runner::run_suite with name: "Advanced"

  2025-08-07T01:42:46.837581Z  INFO s3s_test::runner: Test fixture end, duration_ns: 2942778, case_count: CountSummary { total: 1, passed: 0, failed: 1 }
    at crates/s3s-test/src/runner.rs:157
    in s3s_test::runner::run_fixture with name: "STS"
    in s3s_test::runner::run_suite with name: "Advanced"

  2025-08-07T01:42:46.837696Z  INFO s3s_test::runner: Test suite end, duration_ns: 3770750, fixture_count: CountSummary { total: 1, passed: 0, failed: 1 }
    at crates/s3s-test/src/runner.rs:114
    in s3s_test::runner::run_suite with name: "Advanced"

  2025-08-07T01:42:46.837700Z  INFO s3s_test::runner: Test end, duration_ns: 7290559793, suite_count: CountSummary { total: 2, passed: 0, failed: 2 }
    at crates/s3s-test/src/runner.rs:76

FAILED 1763.527ms [Basic/Essential/test_list_buckets]
  ERROR Failed: service error
FAILED 2498.021ms [Basic/Essential/test_list_objects]
  ERROR Failed: service error
FAILED 1369.927ms [Basic/Essential/test_get_object]
  ERROR Failed: service error
FAILED 5631.614ms [Basic/Essential]
FAILED 1612.854ms [Basic/Put]
FAILED 7286.738ms [Basic]
FAILED    2.848ms [Advanced/STS/test_assume_role]
  ERROR Failed: service error
FAILED    2.943ms [Advanced/STS]
FAILED    3.771ms [Advanced]
FAILED 7290.560ms
Error: Process completed with exit code 1.

@Sambit003
Copy link
Author

@Sambit003

It looks like the unit test failed.


Backtrace:
  2025-08-07T01:42:46.837516Z  INFO s3s_test::runner: Test case end, summary: FnSummary { result: Err("Failed: service error"), duration_ns: 2809447, duration_ms: 2.809447 }
    at crates/s3s-test/src/runner.rs:177
    in s3s_test::runner::run_case with name: "test_assume_role"
    in s3s_test::runner::run_fixture with name: "STS"
    in s3s_test::runner::run_suite with name: "Advanced"

  2025-08-07T01:42:46.837532Z  INFO s3s_test::runner: Test fixture teardown
    at crates/s3s-test/src/runner.rs:149
    in s3s_test::runner::run_fixture with name: "STS"
    in s3s_test::runner::run_suite with name: "Advanced"

  2025-08-07T01:42:46.837581Z  INFO s3s_test::runner: Test fixture end, duration_ns: 2942778, case_count: CountSummary { total: 1, passed: 0, failed: 1 }
    at crates/s3s-test/src/runner.rs:157
    in s3s_test::runner::run_fixture with name: "STS"
    in s3s_test::runner::run_suite with name: "Advanced"

  2025-08-07T01:42:46.837696Z  INFO s3s_test::runner: Test suite end, duration_ns: 3770750, fixture_count: CountSummary { total: 1, passed: 0, failed: 1 }
    at crates/s3s-test/src/runner.rs:114
    in s3s_test::runner::run_suite with name: "Advanced"

  2025-08-07T01:42:46.837700Z  INFO s3s_test::runner: Test end, duration_ns: 7290559793, suite_count: CountSummary { total: 2, passed: 0, failed: 2 }
    at crates/s3s-test/src/runner.rs:76

FAILED 1763.527ms [Basic/Essential/test_list_buckets]
  ERROR Failed: service error
FAILED 2498.021ms [Basic/Essential/test_list_objects]
  ERROR Failed: service error
FAILED 1369.927ms [Basic/Essential/test_get_object]
  ERROR Failed: service error
FAILED 5631.614ms [Basic/Essential]
FAILED 1612.854ms [Basic/Put]
FAILED 7286.738ms [Basic]
FAILED    2.848ms [Advanced/STS/test_assume_role]
  ERROR Failed: service error
FAILED    2.943ms [Advanced/STS]
FAILED    3.771ms [Advanced]
FAILED 7290.560ms
Error: Process completed with exit code 1.

Yess...i've been diving deep into the issue...i'm fixing them up

@loverustfs
Copy link
Contributor

Yess...i've been diving deep into the issue...i'm fixing them up

@Sambit003
It looks like the unit test failed.


Backtrace:
  2025-08-07T01:42:46.837516Z  INFO s3s_test::runner: Test case end, summary: FnSummary { result: Err("Failed: service error"), duration_ns: 2809447, duration_ms: 2.809447 }
    at crates/s3s-test/src/runner.rs:177
    in s3s_test::runner::run_case with name: "test_assume_role"
    in s3s_test::runner::run_fixture with name: "STS"
    in s3s_test::runner::run_suite with name: "Advanced"

  2025-08-07T01:42:46.837532Z  INFO s3s_test::runner: Test fixture teardown
    at crates/s3s-test/src/runner.rs:149
    in s3s_test::runner::run_fixture with name: "STS"
    in s3s_test::runner::run_suite with name: "Advanced"

  2025-08-07T01:42:46.837581Z  INFO s3s_test::runner: Test fixture end, duration_ns: 2942778, case_count: CountSummary { total: 1, passed: 0, failed: 1 }
    at crates/s3s-test/src/runner.rs:157
    in s3s_test::runner::run_fixture with name: "STS"
    in s3s_test::runner::run_suite with name: "Advanced"

  2025-08-07T01:42:46.837696Z  INFO s3s_test::runner: Test suite end, duration_ns: 3770750, fixture_count: CountSummary { total: 1, passed: 0, failed: 1 }
    at crates/s3s-test/src/runner.rs:114
    in s3s_test::runner::run_suite with name: "Advanced"

  2025-08-07T01:42:46.837700Z  INFO s3s_test::runner: Test end, duration_ns: 7290559793, suite_count: CountSummary { total: 2, passed: 0, failed: 2 }
    at crates/s3s-test/src/runner.rs:76

FAILED 1763.527ms [Basic/Essential/test_list_buckets]
  ERROR Failed: service error
FAILED 2498.021ms [Basic/Essential/test_list_objects]
  ERROR Failed: service error
FAILED 1369.927ms [Basic/Essential/test_get_object]
  ERROR Failed: service error
FAILED 5631.614ms [Basic/Essential]
FAILED 1612.854ms [Basic/Put]
FAILED 7286.738ms [Basic]
FAILED    2.848ms [Advanced/STS/test_assume_role]
  ERROR Failed: service error
FAILED    2.943ms [Advanced/STS]
FAILED    3.771ms [Advanced]
FAILED 7290.560ms
Error: Process completed with exit code 1.

Yess...i've been diving deep into the issue...i'm fixing them up

Thank you for your contribution!

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.

3 participants