public static class BoundsChecker
{
    public static void EnsureRange(long offset, long size, long totalLength, string name)
    {
        if (offset < 0 || size < 0)
        {
            throw new SafetyException($"Negative range for {name}.");
        }

        if (offset > totalLength || size > totalLength || offset + size > totalLength)
        {
            throw new SafetyException($"Out-of-bounds range for {name}. Offset={offset}, Size={size}, Length={totalLength}");
        }
    }

    public static void EnsureCount(int count, int max, string name)
    {
        if (count < 0 || count > max)
        {
            throw new SafetyException($"{name} exceeds safety limit. Count={count}, Max={max}");
        }
    }

    public static void EnsureSeekable(Stream stream)
    {
        if (!stream.CanSeek)
        {
            throw new NotSupportedException("Input stream must be seekable for safe PE parsing.");
        }
    }
}