Skip to content

Silent u16 truncation in symbolic bytecode symbolize functions #291

Closed

Description

@bpowers

Problem

In src/simlin-engine/src/compiler/symbolic.rs, two casts silently truncate values when converting to u16:

  1. symbolize_static_view casts view.base_off (a u32) to u16
  2. symbolize_module_decl casts decl.off (a usize) to u16

Both casts will silently truncate if the value exceeds 65535. For sufficiently large models, this would corrupt the symbolic representation without any error signal.

Why It Matters

The symbolic bytecode path is still development/test-only, but before it goes live to production, this data loss pathway must be eliminated. Silent truncation of offsets corrupts the symbolic information without any diagnostic.

Current State

This is currently dead/scaffold code (only used in tests), so there is no immediate impact. However, this pattern is a correctness risk.

Resolution Approach

Replace the silent casts with explicit bounds checking:

  • Use u16::try_from().unwrap() or similar, which will panic if a value exceeds u16 bounds
  • Or add explicit bounds checking before conversion with proper error handling
  • Add tests that verify large offset values are rejected or handled correctly

Context

Found during code review of PR #289.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions