Skip to content

Instantly share code, notes, and snippets.

View Shnatsel's full-sized avatar

Sergey "Shnatsel" Davidoff Shnatsel

View GitHub Profile
@Shnatsel
Shnatsel / lib.rs
Last active July 18, 2026 21:45
Example of std::simd using the native hardware vector width
#![feature(portable_simd)]
use multiversion::multiversion;
use std::ops::Add;
use std::simd::Simd;
use std::simd::SimdElement;
fn main() {
let mut a = [1.0; 50];
let b = [0.5; 50];
dispatch_native_width(&mut a, &b);
@Shnatsel
Shnatsel / lib.rs
Last active July 13, 2026 13:14
Fearless SIMD trigonometry extension crate prototype
#![no_std]
use core::any::TypeId;
use fearless_simd::{Simd, SimdBase, SimdInto, f32x4, f32x8};
pub trait F32Trig {
fn sin(self) -> Self;
}
@Shnatsel
Shnatsel / Safe SIMD in Rust, even on the inside.md
Created June 22, 2026 14:27
Safe SIMD in Rust, even on the inside.md

This is a mirror of my article which Medium reportedly refuses to show to some people.

Safe SIMD in Rust, even on the inside

Rust’s SIMD abstractions were not as safe as I’d like. Until now.

It’s no secret that raw SIMD intrinsics are unpleasant to use.

You want to write a + b, not this monstrosity:

@Shnatsel
Shnatsel / The unreasonable effectiveness of LLMs for auditing Rust code.md
Created June 20, 2026 18:31
The unreasonable effectiveness of LLMs for auditing Rust code

This is a mirror of my article which Medium apparently refuses to show to some people.

The unreasonable effectiveness of LLMs for auditing Rust code

As a lead of the Rust Secure Code Working Group, I got free access to GPT-5.5 via the Codex for Open Source. Since then I’ve found and reported dozens of issues of varying severity in widely used Rust crates.

Separately, the Rust Foundation security initiative got access to Mythos via Project Glasswing, and their report should also be coming soon. I’ve coordinated with them so that our audit targets would not overlap.

While I haven’t found any truly devastating vulnerabilities, I am very impressed with GPT-5.5 for aud

@Shnatsel
Shnatsel / custom_try_fold.rs
Created October 13, 2023 13:21
An equivalent of `bytes()` using internal iteration
#![feature(try_trait_v2)]
use std::{io::{Write, BufRead}, ops::{Try, ControlFlow}};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let test_file_path = std::env::args_os().nth(1).expect("No input file specified!");
let test_file = std::fs::File::open(test_file_path)?;
let stdout = std::io::stdout();
// Lock the stdout once so we don't have to acquire the lock for every line written, which is slow
let stdout = stdout.lock();
#!/bin/sh
set -e
input="$1"
output1="$(mktemp --tmpdir result_XXXXXXXXXXXXX.ppm)"
output2="$(mktemp --tmpdir result_XXXXXXXXXXXXX.ppm)"
trap "rm -f "$output1" "$output2"" EXIT
if ! yes | /home/shnatsel/Code/zune-image/target/release/zune --safe --input "$input" --out "$output1" >/dev/null 2>&1; then
@Shnatsel
Shnatsel / data.txt
Created May 3, 2020 12:39
all occurrences of 'const_err' on crates.io
parsec-service-0.1.2/build.rs: const_err,
sta-0.2.5/src/lib.rs: pub fn const_error(errormessage: String, exitcode: i32) -> Error {
sta-0.2.5/src/lib.rs: pub fn const_error_noexit(errormessage: String) -> Error {
sta-0.2.5/src/lib.rs: let error = error::const_error_noexit("This is a sample error, beep beep.".to_string());
core_extensions-0.1.16/src_core_extensions/marker_traits.rs: #[allow(const_err)]
core_extensions-0.1.16/src_core_extensions/marker_traits.rs: #[allow(const_err)]
oaidl-0.2.1/src/lib.rs:#![deny(const_err)]
x509-signature-0.3.0/src/lib.rs: const_err,
betrusted-pac-0.0.1/src/lib.rs:#![deny(const_err)]
gd32vf103-pac-0.2.0/src/lib.rs:#![deny(const_err)]
@Shnatsel
Shnatsel / compare.sh
Last active December 16, 2018 19:06
compare two folders with images visually and output mean squared error for each pair
#!/bin/bash
# Usage:
# ./compare.sh folder1 folder2 | grep -v '^[0-9]\.[0-9]\+e-' | grep -v '^0 ' | sort --numeric-sort --reverse
# filters out images with significant differences and sorts them by mean squared error
cd "$1"
for file in $(find * -type f); do
# http://www.imagemagick.org/Usage/compare/
NORMALIZED_DIFFERENCE=$(compare -metric MSE "$file" ../"$2"/"$file" null: 2>&1 | cut -d '(' -f 2 | cut -d ')' -f 1)
@Shnatsel
Shnatsel / uninitialized_memory_different_every_time.patch
Created August 22, 2018 02:02
Patch for libdislocate so that it clobbers every buffer allocated with malloc() with a different value. This allows checking for memory disclosure vulnerabilities in arbitrary code simply by running the operation to check twice and comparing the output.
--- libdislocator.so.c.pristine 2018-08-22 04:43:10.970904951 +0300
+++ libdislocator.so.c 2018-08-22 04:46:06.028396381 +0300
@@ -64,7 +64,7 @@
/* Canary & clobber bytes: */
#define ALLOC_CANARY 0xAACCAACC
-#define ALLOC_CLOBBER 0xCC
+int alloc_clobber_counter = 0;
#define PTR_C(_p) (((u32*)(_p))[-1])
@Shnatsel
Shnatsel / membleed.rs
Last active August 25, 2018 03:16
trivial testcase to notice uninitialized memory use in Rust
use std::vec;
// Use the system allocator so we can substitute it with a custom one via LD_PRELOAD
use std::alloc::System;
#[global_allocator]
static GLOBAL: System = System;
/// Returns the sum of all values in a vector of uninitialized memory
fn sum_uninitialized() -> u64 {
let mut my_vec: Vec<u64> = Vec::with_capacity(2048);