<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gaurav</title>
    <description>The latest articles on DEV Community by Gaurav (@gaurav-sid).</description>
    <link>https://dev.to/gaurav-sid</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3707898%2F2a634d5a-b57c-4ba8-8ae1-be2bb2ab6431.png</url>
      <title>DEV Community: Gaurav</title>
      <link>https://dev.to/gaurav-sid</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gaurav-sid"/>
    <language>en</language>
    <item>
      <title>We Built a Feature We Never Shipped — And That Was the Whole Point</title>
      <dc:creator>Gaurav</dc:creator>
      <pubDate>Fri, 04 Sep 2026 05:01:09 +0000</pubDate>
      <link>https://dev.to/gaurav-sid/we-built-a-feature-we-never-shipped-and-that-was-the-whole-point-2k76</link>
      <guid>https://dev.to/gaurav-sid/we-built-a-feature-we-never-shipped-and-that-was-the-whole-point-2k76</guid>
      <description>&lt;p&gt;Somewhere in the middle of building &lt;a href="https://github.com/GauravS13/KilnForge" rel="noopener noreferrer"&gt;KilnForge&lt;/a&gt;, we wrote a fully working feature, tested it, confirmed it was correct — and then didn't ship it. On purpose. That's not a typo. It's the most honest answer we have to what this post is actually about.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Key Takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We hand-rolled a byte-level EXIF orientation parser, then discovered &lt;code&gt;Bun.Image&lt;/code&gt; already does that internally — shipping ours would have double-rotated every tagged photo&lt;/li&gt;
&lt;li&gt;Three other "obvious" &lt;code&gt;sharp&lt;/code&gt; features don't exist natively in &lt;code&gt;Bun.Image&lt;/code&gt;: a BMP/GIF encoder, a &lt;code&gt;fit: cover&lt;/code&gt; resize mode, and arbitrary-angle rotation — each needed a real, hand-rolled fallback&lt;/li&gt;
&lt;li&gt;We also found a bug in our own reproducible-build proof: 3 compiles produced 3 different hashes, traced to 2 differing bytes out of ~89MB — our own filename, not the build&lt;/li&gt;
&lt;li&gt;Measured, not estimated: KilnForge runs 1.81x–10.22x faster than &lt;code&gt;sharp&lt;/code&gt; on resize/rotate/convert, and 41.73x faster than &lt;code&gt;tar&lt;/code&gt; at unpacking archives — but 1.22x &lt;em&gt;slower&lt;/em&gt; at packing them, published honestly either way&lt;/li&gt;
&lt;li&gt;263 tests, 6,463 assertions, all passing — including differential tests run against real &lt;code&gt;sharp&lt;/code&gt; and real &lt;code&gt;tar&lt;/code&gt; output, not synthetic stand-ins&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How We Verified All of This
&lt;/h2&gt;

&lt;p&gt;Every claim in this post comes from one of three concrete checks, not from reading a changelog:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Direct API probing&lt;/strong&gt; — calling the actual method on the actual installed &lt;a href="https://bun.sh" rel="noopener noreferrer"&gt;Bun&lt;/a&gt; binary (1.4.0) and recording what happens, success or exception, before writing a single line of pipeline code around it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pixel-level differential comparison&lt;/strong&gt; — comparing our output against &lt;code&gt;Bun.Image&lt;/code&gt;'s own native output, byte for byte, on identical source images (used to catch the rotation off-by-half-pixel bug and to confirm the EXIF auto-rotation behavior).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real reference-implementation testing&lt;/strong&gt; — running our output through the same test suite against real &lt;code&gt;sharp&lt;/code&gt; and real &lt;code&gt;tar&lt;/code&gt; output on identical inputs, not synthetic stand-ins, via golden-corpus tests that ship in the repo.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All of it is reproducible: &lt;code&gt;bun test&lt;/code&gt; runs all 263 tests, including the golden-corpus suite, from a clean checkout.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Package We'd Normally Install
&lt;/h2&gt;

&lt;p&gt;If you're processing images on a server, you reach for &lt;a href="https://www.npmjs.com/package/sharp" rel="noopener noreferrer"&gt;&lt;code&gt;sharp&lt;/code&gt;&lt;/a&gt;. It's fast, it's mature, and underneath it's a native addon wrapping libvips — which means a real C build toolchain has to exist on whatever machine installs it. If you're bundling files, you reach for &lt;a href="https://www.npmjs.com/package/tar" rel="noopener noreferrer"&gt;&lt;code&gt;tar&lt;/code&gt;&lt;/a&gt;. Both are exactly the kind of dependency a zero-dependency hackathon exists to prove you don't strictly need.&lt;/p&gt;

&lt;p&gt;So we set out to replace both, using Bun's own native &lt;a href="https://bun.sh/docs" rel="noopener noreferrer"&gt;&lt;code&gt;Bun.Image&lt;/code&gt; and &lt;code&gt;Bun.Archive&lt;/code&gt;&lt;/a&gt; APIs — no &lt;code&gt;sharp&lt;/code&gt;, no &lt;code&gt;tar&lt;/code&gt;, no native build step. &lt;code&gt;dependencies: {}&lt;/code&gt; in &lt;code&gt;package.json&lt;/code&gt;, checked mechanically on every build via a script that scans every import in &lt;code&gt;src/**&lt;/code&gt; and refuses to let either package sneak in. This is our entry for a &lt;a href="https://zerodepshack.com" rel="noopener noreferrer"&gt;zero-dependency hackathon&lt;/a&gt; that scores exactly that kind of mechanical proof over a README claim.&lt;/p&gt;

&lt;p&gt;That part sounds simple in a pitch. It wasn't simple in practice, because &lt;code&gt;Bun.Image&lt;/code&gt; and &lt;code&gt;Bun.Archive&lt;/code&gt; are both very new APIs — days old at the point we started. The write-ups we found while planning disagreed with each other on basic questions, color-profile survival being the clearest example: some sources claimed ICC profiles survive a transcode, others claimed they get stripped. We didn't pick a side. We built a minimal PNG carrying a real color-profile chunk, ran it through &lt;code&gt;Bun.Image&lt;/code&gt;'s own encoder, and checked the output bytes directly. The chunk was gone. One test resolved a contradiction that no amount of re-reading either source would have.&lt;/p&gt;

&lt;p&gt;We decided early that we wouldn't build anything on top of an assumption we hadn't personally verified against the real, installed Bun binary. That decision is the reason this post has a story to tell instead of just a features list.&lt;/p&gt;

&lt;h2&gt;
  
  
  What We Built By Hand
&lt;/h2&gt;

&lt;p&gt;Before writing any pipeline code, we wrote a &lt;strong&gt;Foundation Verification Harness&lt;/strong&gt; — a script that runs real probes against the actual Bun runtime and records what it finds, separate from whether the probe itself crashed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;probe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ProbeResult&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;finding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;detail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;finding&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;detail&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;finding&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;detail&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;finding&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;finding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;detail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`threw unexpectedly: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ok&lt;/code&gt; answers "did this probe run without crashing." &lt;code&gt;finding&lt;/code&gt; answers "what did it actually discover." Those are different questions — a probe can run perfectly cleanly and still report a negative finding, and that's a successful, informative run, not a failure. Every architectural decision downstream got pinned to what this harness actually measured, not to what we assumed going in.&lt;/p&gt;

&lt;p&gt;It's a good thing we did, because several of those assumptions were wrong.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;Bun.Image&lt;/code&gt; has no BMP or GIF encoder
&lt;/h3&gt;

&lt;p&gt;Our original plan was to choose between a PNG channel and a BMP channel for reading and writing raw pixels. Real inspection of &lt;code&gt;Bun.Image.prototype&lt;/code&gt; showed no &lt;code&gt;.bmp()&lt;/code&gt; and no &lt;code&gt;.gif()&lt;/code&gt; method at all — both formats are decode-only. PNG wasn't the &lt;em&gt;preferred&lt;/em&gt; channel. It was the &lt;em&gt;only&lt;/em&gt; one. That meant hand-rolling a real PNG encoder/decoder from scratch: chunk parsing, &lt;code&gt;node:zlib&lt;/code&gt; for the inflate/deflate, scanline filter/unfilter, our own CRC32 — just to get a working raw-pixel round trip.&lt;/p&gt;

&lt;h3&gt;
  
  
  There's no native &lt;code&gt;fit: cover&lt;/code&gt; resize mode
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Bun.Image.resize()&lt;/code&gt; only exposes &lt;code&gt;fill&lt;/code&gt; (stretch to exact dimensions) and &lt;code&gt;inside&lt;/code&gt; (aspect-preserving, fits within the box). There's no crop-to-fill. We built it ourselves — compute the overscale factor that would cover the target box while preserving aspect ratio, resize with the native &lt;code&gt;fill&lt;/code&gt; mode, then center-crop the raw pixel buffer down to size:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;resizeCover&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Bun&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;targetWidth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;targetHeight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Bun&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Image&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;meta&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;targetWidth&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;targetHeight&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;overW&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;overH&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;resized&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;overW&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;overH&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fill&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rgba&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;toRGBA&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resized&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cropped&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;cropCenter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rgba&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;targetWidth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;targetHeight&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;loadImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;fromRGBA&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cropped&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Arbitrary-angle rotation isn't native either
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Bun.Image.rotate(45)&lt;/code&gt; genuinely throws — "only multiples of 90 are supported" — confirmed directly, not assumed from a changelog. We wrote our own rotation via an inverse coordinate transform, and it had a bug worth mentioning: the first version was wrong by exactly half a pixel, because it treated a pixel's raw integer index as its coordinate instead of the &lt;em&gt;center&lt;/em&gt; of the cell that pixel occupies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Pixel index i occupies the continuous interval [i, i+1) with its&lt;/span&gt;
&lt;span class="c1"&gt;// CENTER at i+0.5 — sampling must rotate from that center, not from&lt;/span&gt;
&lt;span class="c1"&gt;// the raw integer index, or the whole mapping is off by half a pixel&lt;/span&gt;
&lt;span class="c1"&gt;// (verified by hand against Bun.Image's native rotate(90), which has&lt;/span&gt;
&lt;span class="c1"&gt;// an exact, unambiguous discrete answer to check against).&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;relY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;dy&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;destCenterY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;relX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;dx&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;destCenterX&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;srcX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;relX&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;cos&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;relY&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;sin&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;srcCenterX&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;srcY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;relX&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;sin&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;relY&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;cos&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;srcCenterY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That one-line fix (&lt;code&gt;+ 0.5&lt;/code&gt;) took a 58% pixel mismatch against &lt;code&gt;Bun.Image&lt;/code&gt;'s own native &lt;code&gt;rotate(90)&lt;/code&gt; — used as a cross-check oracle for the 90° case, which &lt;em&gt;is&lt;/em&gt; native — down to zero mismatches across every test we threw at it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Feature We Never Shipped
&lt;/h2&gt;

&lt;p&gt;Here's the part we're actually proudest of, and it's not a feature that shipped — it's one that didn't.&lt;/p&gt;

&lt;p&gt;We built a complete, tested, byte-level EXIF orientation parser by hand: reads the JPEG APP1 marker, walks the TIFF structure, handles both byte orders (Intel and Motorola), covers all eight orientation values, and converts the result into the correct rotate-and-flip transform. It worked. It passed its own test suite standalone. Every image-processing library we've ever used needs this, so naturally we assumed &lt;code&gt;Bun.Image&lt;/code&gt; would need it wired in too.&lt;/p&gt;

&lt;p&gt;Before wiring it into the live request pipeline, we ran one more check — because by this point "test it before you trust it" was the whole method, not just something we did once at the start. We fed a real EXIF-tagged photo straight into &lt;code&gt;Bun.Image&lt;/code&gt; with no correction of our own, and checked what came out.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Bun.Image&lt;/code&gt; had already rotated it. Correctly. On its own, during decode.&lt;/p&gt;

&lt;p&gt;We confirmed it two ways: &lt;code&gt;metadata()&lt;/code&gt; reported swapped width and height immediately after decode, and a direct pixel comparison against a manual native &lt;code&gt;.rotate(90)&lt;/code&gt; on the same source came back with zero mismatches. &lt;code&gt;Bun.Image&lt;/code&gt; auto-applies EXIF orientation internally — nobody advertised that clearly anywhere we'd read, but the runtime doesn't lie the way documentation sometimes does.&lt;/p&gt;

&lt;p&gt;If we'd shipped the original plan — wiring our own parser into the request pipeline on top of that — every single EXIF-tagged photo uploaded to the service would have been rotated &lt;strong&gt;twice&lt;/strong&gt;. Once by &lt;code&gt;Bun.Image&lt;/code&gt;, invisibly, during decode. Once by us, right after. The bug wouldn't have been subtle. It would have been &lt;em&gt;every photo, every time&lt;/em&gt;. And it would have passed casual testing anyway — anyone checking with an un-rotated test image would have seen nothing wrong.&lt;/p&gt;

&lt;p&gt;The parser still exists in the codebase today, fully tested, completely real — just deliberately disconnected from the request pipeline, with a comment explaining exactly why:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// NOTE: this module deliberately does NOT auto-apply EXIF orientation&lt;/span&gt;
&lt;span class="c1"&gt;// before handing bytes to Bun.Image. Empirical testing (see&lt;/span&gt;
&lt;span class="c1"&gt;// src/image/exif.ts's module comment) found Bun.Image already applies&lt;/span&gt;
&lt;span class="c1"&gt;// EXIF orientation correction internally during decode — confirmed via&lt;/span&gt;
&lt;span class="c1"&gt;// metadata() reporting swapped dimensions immediately and 0 pixel&lt;/span&gt;
&lt;span class="c1"&gt;// mismatches against a manual native .rotate(90) on the same source.&lt;/span&gt;
&lt;span class="c1"&gt;// Calling our own applyOrientation() on top of that would double-rotate&lt;/span&gt;
&lt;span class="c1"&gt;// every EXIF-tagged upload.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's the whole point of this post, if it has one: the win here wasn't building the parser. It was catching, before a single real user ever touched it, that building it into the pipeline would have been the bug.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Bug in Our Own Proof
&lt;/h2&gt;

&lt;p&gt;We found one more bug the same way, and it wasn't in the product — it was in our own evidence.&lt;/p&gt;

&lt;p&gt;One of the bonuses this hackathon offers is a &lt;em&gt;reproducible build&lt;/em&gt;: compile the same source three separate times, hash each binary, prove they're identical. We ran it. We got three different SHA-256 hashes. By the letter of the check, that's a fail.&lt;/p&gt;

&lt;p&gt;Instead of writing that down as an honest limitation and moving on, we diffed the three binaries byte for byte. Out of roughly 89 megabytes, exactly two bytes were different. One of them was plain, readable text — our own &lt;code&gt;--outfile&lt;/code&gt; filename, which Bun's compiler embeds into the binary as an internal module path. We'd given each of the three test builds a different output filename, so the &lt;em&gt;test&lt;/em&gt; introduced the only variance it then measured.&lt;/p&gt;

&lt;p&gt;Fixed it by using an identical filename across three separate temp directories instead, and reran. Byte-for-byte identical. Verified with &lt;code&gt;cmp&lt;/code&gt;, zero differences. The build had been reproducible the entire time — our test of it hadn't been.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Real Numbers
&lt;/h2&gt;

&lt;p&gt;Bun's own release coverage cites roughly 1.2x–1.4x faster resize/convert performance for &lt;code&gt;Bun.Image&lt;/code&gt; versus &lt;code&gt;sharp&lt;/code&gt;. Our numbers below are our own independent run, on our own fixtures — not a substitute for that public figure, cited alongside it rather than instead of it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6xhl4nbezxkyqoz5pks7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6xhl4nbezxkyqoz5pks7.png" alt=" " width="800" height="539"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th&gt;KilnForge (mean)&lt;/th&gt;
&lt;th&gt;sharp (mean)&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;resize 64×48 → 20×20 (fill)&lt;/td&gt;
&lt;td&gt;0.23ms&lt;/td&gt;
&lt;td&gt;2.35ms&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;10.22x faster&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;rotate 90° (20×40)&lt;/td&gt;
&lt;td&gt;0.11ms&lt;/td&gt;
&lt;td&gt;0.99ms&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;9.00x faster&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;convert JPEG → WebP (q85)&lt;/td&gt;
&lt;td&gt;0.30ms&lt;/td&gt;
&lt;td&gt;1.15ms&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;3.83x faster&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;resize 256×256 → 30×30 (cover)&lt;/td&gt;
&lt;td&gt;1.87ms&lt;/td&gt;
&lt;td&gt;3.39ms&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1.81x faster&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation (archive)&lt;/th&gt;
&lt;th&gt;KilnForge (mean)&lt;/th&gt;
&lt;th&gt;tar (mean)&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;unpack&lt;/td&gt;
&lt;td&gt;0.22ms&lt;/td&gt;
&lt;td&gt;9.18ms&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;41.73x faster&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;pack (5 files × 5KB)&lt;/td&gt;
&lt;td&gt;0.11ms&lt;/td&gt;
&lt;td&gt;0.09ms&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1.22x slower&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;We didn't publish only the numbers that flatter us. On the archive side, unpacking a tarball through &lt;code&gt;Bun.Archive&lt;/code&gt; runs 41.73x faster than &lt;code&gt;tar&lt;/code&gt; — mostly because &lt;code&gt;tar&lt;/code&gt;'s own API extracts to real disk I/O per file while ours stays in memory, a genuine architectural difference. But &lt;em&gt;packing&lt;/em&gt; a tarball is 1.22x &lt;strong&gt;slower&lt;/strong&gt; with our implementation than with &lt;code&gt;tar&lt;/code&gt;. That's a small, real margin on a handful of small files, and we're stating it instead of quietly leaving it out of the chart.&lt;/p&gt;

&lt;p&gt;None of these numbers are estimates. They come from real differential tests — our output compared directly against real &lt;code&gt;sharp&lt;/code&gt; and real &lt;code&gt;tar&lt;/code&gt; output on the same inputs, both kept as &lt;code&gt;devDependencies&lt;/code&gt; used only by the benchmark and test scripts, never imported by anything that ships. A script that scans every import in the actual service code confirms that split mechanically, not by us promising it. All 263 tests pass, 6,463 assertions total, across 34 files.&lt;/p&gt;

&lt;p&gt;None of this is worth much without seeing it actually run. Here's the real thing — server up from a clean checkout, resize/watermark/convert/&lt;code&gt;/batch&lt;/code&gt; all live, the Foundation Verification Harness's own output on camera:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/rdMpBf4QRwg" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  What Going Zero-Dependency Actually Costs
&lt;/h2&gt;

&lt;p&gt;The honest answer to "what did it take to replace &lt;code&gt;sharp&lt;/code&gt; and &lt;code&gt;tar&lt;/code&gt;" isn't "we're faster" — though on most operations, measured fairly, we are. The honest answer is that a mature library like &lt;code&gt;sharp&lt;/code&gt; has quietly handled a decade of edge cases you never think about until you're the one who has to handle them: EXIF orientation, crop-to-fill resizing, arbitrary rotation angles, alpha-safe format conversion, decompression-bomb protection. None of that goes away when you drop the dependency. It just moves onto your desk.&lt;/p&gt;

&lt;p&gt;The only way we found to know we'd actually covered those edge cases — instead of just assuming our replacement code was equivalent — was to keep testing against the real runtime and the real reference implementation, the whole way through. That's what caught the EXIF bug before it shipped. That's what caught the reproducibility bug in our own proof. Neither of those would show up in a features list. Both of them are the actual work.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;We're The Vighnahartas&lt;/strong&gt; — a team entry for Track F of the &lt;a href="https://zerodepshack.com" rel="noopener noreferrer"&gt;Zero Dependency Hackathon&lt;/a&gt; (Aug 28–31, 2026). KilnForge is the project this post is about. Everything referenced here — the code, the tests, the benchmark scripts — is in the &lt;a href="https://github.com/GauravS13/KilnForge" rel="noopener noreferrer"&gt;public repo&lt;/a&gt;, built on Bun 1.4.0.&lt;/p&gt;

</description>
      <category>hackathonraptors</category>
      <category>bunjs</category>
      <category>zerodependencies</category>
      <category>showdev</category>
    </item>
    <item>
      <title>I Ported an 830-Star Python Library to Rust and the Fuzzer Found 12 Bugs — All of Them Mine 🦀</title>
      <dc:creator>Gaurav</dc:creator>
      <pubDate>Sat, 08 Aug 2026 04:45:54 +0000</pubDate>
      <link>https://dev.to/gaurav-sid/i-ported-an-830-star-python-library-to-rust-and-the-fuzzer-found-12-bugs-all-of-them-mine-3ofe</link>
      <guid>https://dev.to/gaurav-sid/i-ported-an-830-star-python-library-to-rust-and-the-fuzzer-found-12-bugs-all-of-them-mine-3ofe</guid>
      <description>&lt;p&gt;&lt;em&gt;9,549 differential fuzz cases against the real Python original. Zero divergences. Twelve bugs found — every single one was something I wrote, not something Python did.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fok3imrsaprx9hiuloste.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fok3imrsaprx9hiuloste.gif" alt="tinytag-rs terminal demo" width="799" height="561"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/tinytag/tinytag" rel="noopener noreferrer"&gt;tinytag&lt;/a&gt; is an 830-star, zero-dependency Python library that reads tags and audio properties out of WAV, AIFF, FLAC, MP3, Ogg, MP4, and WMA files. I picked it on purpose, not at random: six binary formats in one small, well-tested codebase means six different byte-layout quirks, six different chances to get "close enough" instead of exactly right — a good stress test for what "behavioral equivalence" actually costs, not just what it means in theory. For &lt;a href="https://coderesurrection.com/2026/" rel="noopener noreferrer"&gt;Port Mortem / Code Resurrection 2026&lt;/a&gt; (Track D, Python → Rust), I rewrote six of those seven formats from scratch — no &lt;code&gt;libpython&lt;/code&gt;, no PyO3, no shortcuts — and checked every claim below against the real source files in this repo, not memory.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Key Takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;9,549 differential fuzz cases against the real Python original, 0 divergences, in the last qualifying 65-second run (&lt;a href="https://github.com/GauravS13/tinytag-rs/blob/main/fuzz/log.txt" rel="noopener noreferrer"&gt;fuzz/log.txt&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;3 real bugs in upstream tinytag, found by fuzzing, reproduced faithfully — not fixed, because matching Python's actual output is the scoring target here&lt;/li&gt;
&lt;li&gt;12 bugs the fuzzer found in this port during development, all fixed before this was written&lt;/li&gt;
&lt;li&gt;0 &lt;code&gt;unsafe&lt;/code&gt; blocks, 0 dependencies, 1.65x average speedup, honestly measured&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  👀 What This Thing Actually Does, in 10 Seconds
&lt;/h2&gt;

&lt;p&gt;Before any of the bug stories, here's the whole point of the project in one command. Point the CLI at a real MP3, and it reads the tags straight out of the file — no metadata database, no network call, just parsing bytes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;./target/release/tinytag tests/samples/cbr.mp3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"filename"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"cbr.mp3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"filesize"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;8186&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"mime_type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"audio/mpeg"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"is_lossless"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"duration"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.47020408163265304&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"channels"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"bitrate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;127.99548611111112&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"samplerate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;44100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"artist"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Basshunter"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"album"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"I Can Walk On Water I Can Fly"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"I Can Walk On Water I Can Fly"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"track"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"genre"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Dance"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"year"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"2007"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"comment"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Ripped by THSLIVE"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Real output, from a real fixture file in this repo. That's the entire contract: same file in, same JSON out, whether you run the Python original or this Rust port. Everything below is the story of how hard that "same" turned out to be to actually prove — and where it wasn't quite the case yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  🎯 9,549 Cases, Zero Divergences — Here's How I Checked
&lt;/h2&gt;

&lt;p&gt;The scoring target isn't "does it work" — it's "does it produce byte-for-byte identical output to the Python original, on the same inputs, including the malformed ones." That bar is what surfaced almost everything interesting in this project.&lt;/p&gt;

&lt;p&gt;To check it, I built a differential fuzz harness (&lt;code&gt;src/bin/fuzz_harness.rs&lt;/code&gt;) that mutates real audio fixtures and runs both the vendored Python original and the Rust port against the exact same bytes, then diffs the structured output field by field. It doesn't link Python into the Rust binary — the rules explicitly disallow that — it spawns a real CPython subprocess and compares against it, which is the honest shape of differential testing.&lt;/p&gt;

&lt;p&gt;Last qualifying run, quoted directly from &lt;a href="https://github.com/GauravS13/tinytag-rs/blob/main/fuzz/log.txt" rel="noopener noreferrer"&gt;fuzz/log.txt&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;differential fuzz run started (rust-orchestrated), seed=1785680270143253800
seed corpus: 206 fixtures (full in-scope set, see fuzz_harness.rs)


9549 cases run over 65.0s
0 divergences found
ZERO DIVERGENCES
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;177 unit tests, each traced 1:1 to an expected value in upstream's own &lt;code&gt;test_all.py&lt;/code&gt; — not hand-guessed — plus that fuzz run, are the actual evidence of correctness here, not "I read the code carefully."&lt;/p&gt;

&lt;h2&gt;
  
  
  🐛 The Fuzzer Found 12 Bugs. All of Them Were Mine.
&lt;/h2&gt;

&lt;p&gt;The single biggest source of divergence across this whole project was my own instinct to write &lt;em&gt;more defensive&lt;/em&gt; Rust than the Python original actually is. Twelve times, the fuzzer caught it. A representative few, documented in full in &lt;a href="https://github.com/GauravS13/tinytag-rs/blob/main/DECISIONS.md" rel="noopener noreferrer"&gt;DECISIONS.md&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bug one: AIFF's sample rate flipped across a rounding boundary, because of a function name one letter off from the right one.&lt;/strong&gt; Here's the actual line that shipped first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;sr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mantissa&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;2f64&lt;/span&gt;&lt;span class="nf"&gt;.powi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exp&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;0x3FFF&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;63&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;powi&lt;/code&gt; and &lt;code&gt;powf&lt;/code&gt; both raise a number to a power — the difference is &lt;code&gt;powi&lt;/code&gt; takes an integer exponent and uses a fast approximation, while &lt;code&gt;powf&lt;/code&gt; takes a float exponent and routes through the platform's real &lt;code&gt;pow()&lt;/code&gt;. Rust is explicit that &lt;code&gt;powi&lt;/code&gt; is &lt;em&gt;not&lt;/em&gt; guaranteed to be correctly rounded. Python's &lt;code&gt;2 ** negative_int&lt;/code&gt; always goes the &lt;code&gt;pow()&lt;/code&gt; route — the &lt;code&gt;powf&lt;/code&gt; route. Nine times out of ten that difference is invisible. But right at the edge of &lt;code&gt;u32::MAX&lt;/code&gt;, that tiny rounding error was enough to flip a truncated integer by exactly one — and "one over the line" made Rust reject a sample rate Python happily accepted. The fix ended up needing exact integer arithmetic instead of floats at all, once fuzzing pushed on it hard enough (full diff in the commit history; the one-letter version above is the part that actually mattered). Found by fuzzing mutated exponent bytes in &lt;code&gt;no_audio.aiff&lt;/code&gt; (&lt;a href="https://github.com/GauravS13/tinytag-rs/blob/main/DECISIONS.md" rel="noopener noreferrer"&gt;DECISIONS.md #14e&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bug two, and the one that never seemed to fully die: MP4's atom-tree traversal.&lt;/strong&gt; More on that below — it's worth its own section, because "found it, fixed it" undersells what actually happened.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bug three: a too-short WAV &lt;code&gt;fact&lt;/code&gt; chunk returned an empty value instead of raising an error, like Python does.&lt;/strong&gt; My first instinct was to add a safety check — "if the chunk is at least 4 bytes, read it; otherwise skip." That felt like good defensive programming. It was also wrong. Python's own &lt;code&gt;unpack_from('I', chunk)&lt;/code&gt; has no such check: a chunk shorter than 4 bytes just raises &lt;code&gt;struct.error&lt;/code&gt;, which upstream converts into a real parse error. The fixed version reads exactly like that — no polite skip, just propagate the error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Matches upstream's unguarded `unpack_from('I', chunk)` — a too-short&lt;/span&gt;
&lt;span class="c1"&gt;// buffer is a real parse error there (struct.error -&amp;gt; ParseError), not&lt;/span&gt;
&lt;span class="c1"&gt;// something to skip gracefully.&lt;/span&gt;
&lt;span class="n"&gt;num_samples&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;u32_le&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That &lt;code&gt;?&lt;/code&gt; at the end is doing the actual work: it means "if this read fails, stop and hand the error up" — no fallback, no default value, exactly what Python does when &lt;code&gt;struct.unpack_from&lt;/code&gt; blows up (&lt;a href="https://github.com/GauravS13/tinytag-rs/blob/main/DECISIONS.md" rel="noopener noreferrer"&gt;DECISIONS.md #14a&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;The pattern underneath all twelve: Rust's standard tools (&lt;code&gt;read_exact&lt;/code&gt;, bounds-checked slicing, length guards) nudge you toward code that's &lt;em&gt;more correct&lt;/em&gt; than the reference by default. For a behavioral-equivalence port, that's a bug class of its own — every one of these had to be found by actually running the same corrupted bytes through both implementations, not by code review.&lt;/p&gt;

&lt;h2&gt;
  
  
  🕳️ The Edge Case That Took the Longest to Actually Nail
&lt;/h2&gt;

&lt;p&gt;Every other bug in this post, I fixed once and it stayed fixed. MP4's atom-tree traversal took multiple separate rounds, across seven different fuzzed files, before it actually held — and each time I thought it was done, a new mutated &lt;code&gt;.m4a&lt;/code&gt; would find another angle on the same underlying mistake.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcwo710otfwm6twpfk3zh.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcwo710otfwm6twpfk3zh.gif" alt="Terminal recording of tinytag-rs parsing a corrupted MP4/M4A file and correctly recovering tags after a mid-atom corruption" width="800" height="699"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The root problem: MP4 files are nested trees of "atoms" (&lt;code&gt;moov&lt;/code&gt; → &lt;code&gt;udta&lt;/code&gt; → &lt;code&gt;meta&lt;/code&gt; → &lt;code&gt;ilst&lt;/code&gt;, and so on), and Python's traversal tracks two numbers per level — the file handle's &lt;em&gt;real&lt;/em&gt; read position, and a &lt;em&gt;logical&lt;/em&gt; position it's supposed to be at. On well-formed files those two numbers never disagree, so the distinction is invisible. On a corrupted file, they can legitimately drift apart: a header read that fails immediately still &lt;em&gt;consumes&lt;/em&gt; bytes from the stream, even though the code that failed never got to use them. Python just keeps reading from wherever the handle actually sits after that — it never tries to force the two numbers back in sync.&lt;/p&gt;

&lt;p&gt;My first version &lt;em&gt;did&lt;/em&gt; try to force them back in sync. It looked like the responsible thing to do — reset to each atom's declared end after every step, like a checkpoint. It was exactly backwards: forcing a resync meant every parent atom kept re-reading the same corrupted bytes instead of drifting past them the way Python does, so a corruption Python shrugs off and recovers from (going on to find real tags further in the file) made my port just... stop, silently returning less than it should have.&lt;/p&gt;

&lt;p&gt;The fix that actually held is one line of discipline, applied consistently everywhere a position gets threaded through:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;curr_pos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;on_atom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;curr_pos&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Always take the &lt;em&gt;actual&lt;/em&gt; resulting position back from whatever just ran — never assume it matches what you expected going in. &lt;code&gt;skip_to&lt;/code&gt;, the function that skips a genuinely unrecognized atom, follows the same rule: a relative seek from wherever the reader currently is, never an absolute jump to a precomputed value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="n"&gt;skip_to&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;R&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Seek&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;R&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;atom_size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ParseError&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;pos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="nf"&gt;.seek&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;SeekFrom&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Current&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;atom_size&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;i64&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pos&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple once it's written down. What made it take multiple rounds is that the bug doesn't announce itself as one bug — it shows up as a &lt;em&gt;different&lt;/em&gt; symptom depending on which atom happens to be corrupted and which sibling atom comes after it: sometimes a missing tag, sometimes a whole &lt;code&gt;covr&lt;/code&gt; (cover art) atom's image data getting mis-skipped because a &lt;em&gt;child&lt;/em&gt; atom inside it was independently corrupted (&lt;a href="https://github.com/GauravS13/tinytag-rs/blob/main/DECISIONS.md" rel="noopener noreferrer"&gt;DECISIONS.md #14g&lt;/a&gt;). Each new fuzzed file (&lt;code&gt;multi_value.m4a&lt;/code&gt;, &lt;code&gt;classical.m4a&lt;/code&gt;, &lt;code&gt;mixed_case_atoms.m4a&lt;/code&gt;, &lt;code&gt;xmp_empty.m4a&lt;/code&gt;, &lt;code&gt;test2.m4a&lt;/code&gt;, &lt;code&gt;mvhd_version_1.m4a&lt;/code&gt;, and finally &lt;code&gt;mpeg4_with_image.m4a&lt;/code&gt;) looked like a new bug the first time it failed. It wasn't — it was the same root cause, wearing a different fixture each time, until the "always return the real position" rule got applied everywhere instead of just where the first failure pointed (&lt;a href="https://github.com/GauravS13/tinytag-rs/blob/main/DECISIONS.md" rel="noopener noreferrer"&gt;DECISIONS.md #14f, #14g&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  🔬 The Bug I Found in an 830-Star Library (and Didn't Fix)
&lt;/h2&gt;

&lt;p&gt;Three real bugs in upstream tinytag, all found by fuzzing, all left exactly as-is in the Rust port. That's deliberate: fixing any of them would make the port diverge from Python's real output on that input, which is the opposite of what's being measured.&lt;/p&gt;

&lt;p&gt;The one worth reading in full: &lt;strong&gt;MP4's &lt;code&gt;gnre&lt;/code&gt; atom has a genuine off-by-one bug, and it's the kind every programmer has written at 2am.&lt;/strong&gt; Upstream reads a 2-byte genre index, subtracts 1 (MP4 genre codes are 1-indexed), and looks it up in a genre table. It checks that the index isn't &lt;em&gt;too big&lt;/em&gt; — but never checks that it isn't negative:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;u16_be&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;crate&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;id3v1&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;GENRES&lt;/span&gt;&lt;span class="nf"&gt;.len&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;i64&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;i64&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;real_idx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;usize&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;usize&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;genre&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;crate&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;id3v1&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;GENRES&lt;/span&gt;&lt;span class="nf"&gt;.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;real_idx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;tag&lt;/span&gt;&lt;span class="nf"&gt;.set_str_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"genre"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;genre&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.to_string&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Walk through it with a stored value of &lt;code&gt;0&lt;/code&gt;, meaning "no genre set": &lt;code&gt;idx = 0 - 1 = -1&lt;/code&gt;. The bounds check &lt;code&gt;idx &amp;lt; len&lt;/code&gt; passes fine (&lt;code&gt;-1&lt;/code&gt; is less than the table length). Then &lt;code&gt;real_idx = len + idx&lt;/code&gt; — Python's negative-indexing behavior, deliberately reproduced here — lands on the &lt;em&gt;last&lt;/em&gt; entry in the genre table, "Anime" in this pinned version. So a file that explicitly says "no genre" ends up tagged as Anime. Nothing in the original code marks &lt;code&gt;0&lt;/code&gt; as meaning "give me the last genre" — it reads exactly like a missing &lt;code&gt;if idx &amp;lt; 0: return&lt;/code&gt; that nobody caught, on either side, for years. This port keeps it exactly as-is, on purpose (&lt;a href="https://github.com/GauravS13/tinytag-rs/blob/main/DECISIONS.md" rel="noopener noreferrer"&gt;DECISIONS.md #18a&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;The other two, same treatment: an ID3v2 extended-header seek hardcoded to skip &lt;code&gt;- 6&lt;/code&gt; bytes regardless of how many were actually available (wrong offset on truncation, &lt;a href="https://github.com/GauravS13/tinytag-rs/blob/main/DECISIONS.md" rel="noopener noreferrer"&gt;#17&lt;/a&gt;), and track/disc &lt;code&gt;"X/Y"&lt;/code&gt; splitting that silently discards a third slash-segment via Python's &lt;code&gt;split('/')[:2]&lt;/code&gt; (&lt;a href="https://github.com/GauravS13/tinytag-rs/blob/main/DECISIONS.md" rel="noopener noreferrer"&gt;#18&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚡ 1.65x Faster, and I'm Not Going to Oversell It
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx77rb3qq4kjo3obb71nd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx77rb3qq4kjo3obb71nd.png" alt="Horizontal bar chart of Rust vs Python parse speed per file, ranging from 1.37x to 2.00x, overall average 1.65x" width="799" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Per-file speedup, Rust vs Python, 200 iterations per file. Overall average: 1.65x. Source: &lt;a href="https://github.com/GauravS13/tinytag-rs/blob/main/bench/results.json" rel="noopener noreferrer"&gt;bench/results.json&lt;/a&gt;, methodology in &lt;a href="https://github.com/GauravS13/tinytag-rs/blob/main/bench/methodology.md" rel="noopener noreferrer"&gt;bench/methodology.md&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;File&lt;/th&gt;
&lt;th&gt;Python ns/call&lt;/th&gt;
&lt;th&gt;Rust ns/call&lt;/th&gt;
&lt;th&gt;Speedup&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;vbr_xing_header.mp3&lt;/td&gt;
&lt;td&gt;75,714&lt;/td&gt;
&lt;td&gt;37,786&lt;/td&gt;
&lt;td&gt;2.00x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;flac453sStereo.flac&lt;/td&gt;
&lt;td&gt;78,752&lt;/td&gt;
&lt;td&gt;40,715&lt;/td&gt;
&lt;td&gt;1.93x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;vbri.mp3&lt;/td&gt;
&lt;td&gt;133,237&lt;/td&gt;
&lt;td&gt;72,671&lt;/td&gt;
&lt;td&gt;1.83x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;M1F1-mulawC-AFsp.afc&lt;/td&gt;
&lt;td&gt;71,670&lt;/td&gt;
&lt;td&gt;40,502&lt;/td&gt;
&lt;td&gt;1.77x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;test.wav&lt;/td&gt;
&lt;td&gt;59,566&lt;/td&gt;
&lt;td&gt;34,668&lt;/td&gt;
&lt;td&gt;1.72x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;test3sMono.wav&lt;/td&gt;
&lt;td&gt;62,809&lt;/td&gt;
&lt;td&gt;36,550&lt;/td&gt;
&lt;td&gt;1.72x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;flac1sMono.flac&lt;/td&gt;
&lt;td&gt;84,086&lt;/td&gt;
&lt;td&gt;60,926&lt;/td&gt;
&lt;td&gt;1.38x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;UTF16.mp3&lt;/td&gt;
&lt;td&gt;151,569&lt;/td&gt;
&lt;td&gt;110,596&lt;/td&gt;
&lt;td&gt;1.37x&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Overall: &lt;strong&gt;1.65x&lt;/strong&gt; faster than the Python original, averaged across an 8-file workload spanning WAV/AIFF/FLAC/MP3. That's not dramatic, and I'm not going to pretend it is. Both implementations do the same fundamentally small, byte-shuffling work — parsing a WAV chunk header or an ID3v2 frame is a handful of comparisons and a slice index, not a hot numeric loop where Rust routinely wins by 10-50x over CPython. The pattern that does show up consistently: files with more tag frames to walk (&lt;code&gt;UTF16.mp3&lt;/code&gt;, 1.37x) show a smaller speedup than files that are mostly audio-property parsing with few or no frames (&lt;code&gt;vbr_xing_header.mp3&lt;/code&gt;, 2.00x) — consistent with per-frame Python interpreter overhead being the more meaningful cost driver here, not some inherent parsing-algorithm gap. Real, reproducible, not cherry-picked, and the honest headline is "correctly and safely faster," not "wildly faster."&lt;/p&gt;

&lt;h2&gt;
  
  
  🚧 The One Thing I Couldn't Fix
&lt;/h2&gt;

&lt;p&gt;One disclosed, un-fixed edge case: AIFF's extended-precision sample rate can, on sufficiently corrupted input, exceed &lt;code&gt;u32::MAX&lt;/code&gt;. Python's arbitrary-precision &lt;code&gt;int&lt;/code&gt; represents that value exactly (values like 10³³ Hz have shown up under fuzzing — obviously not a real sample rate). Rust's &lt;code&gt;samplerate: u32&lt;/code&gt; genuinely cannot. Rather than wrapping to garbage via a lossy cast, this port declines the value (&lt;code&gt;None&lt;/code&gt;) when it would overflow. It's a real language-capability limit, not a bug — and it's rare enough that a typical 65-second fuzz run doesn't always hit it, but no real-world AIFF file comes anywhere near this range either (&lt;a href="https://github.com/GauravS13/tinytag-rs/blob/main/DECISIONS.md" rel="noopener noreferrer"&gt;DECISIONS.md #15&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;You might expect an "unsafe block I couldn't remove" story here — there isn't one. This port has zero &lt;code&gt;unsafe&lt;/code&gt; blocks; byte-level tag parsing doesn't need raw pointers, and the format-tree traversal work stayed entirely inside safe, bounds-checked slices the whole way through. The equivalent trade-off isn't a memory-safety compromise, it's the one directly above: a case where "faithful to Python's exact output" and "representable in Rust's type system" genuinely conflict, and something had to give. That's the actual cost of this port, not an unsafe block.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔄 The Decision I'd Take Back
&lt;/h2&gt;

&lt;p&gt;If I'm honest about one call I got wrong: I started the fuzz and benchmark harnesses in Python.&lt;/p&gt;

&lt;p&gt;That felt reasonable at the time — the harness needs to spawn a reference Python process anyway, so writing the orchestration logic (mutate a fixture, run both sides, diff the output, report) in Python too meant one language for that whole layer, ~369 lines split across &lt;code&gt;fuzz/diff_fuzz.py&lt;/code&gt; and &lt;code&gt;bench/run_bench.py&lt;/code&gt;. It worked. It just wasn't fast, because every single fuzz case meant spawning a fresh Python subprocess — and that per-case process-spawn cost dominated the actual work being measured.&lt;/p&gt;

&lt;p&gt;Partway through, I rewrote both as Rust binaries (&lt;code&gt;src/bin/fuzz_harness.rs&lt;/code&gt;, &lt;code&gt;src/bin/bench.rs&lt;/code&gt;) that spawn Python exactly once and feed it an embedded reference-oracle script, instead of once per case. Same total amount of "real Python running real Python code" — just amortized across the whole run instead of paid per-case. The result wasn't just cleaner: the Rust-orchestrated harness ran roughly &lt;strong&gt;2x more cases in the same wall-clock time&lt;/strong&gt;, and that extra throughput is &lt;em&gt;directly&lt;/em&gt; how two of the twelve bugs above (&lt;a href="https://github.com/GauravS13/tinytag-rs/blob/main/DECISIONS.md" rel="noopener noreferrer"&gt;#14a, #14b&lt;/a&gt;) got found at all — the original Python-orchestrated version's slower cases-per-second never reached them inside a qualifying run's time budget.&lt;/p&gt;

&lt;p&gt;If I started over, the harness would be a Rust binary from the first commit, not a mid-build rewrite. Not because the Python version was wrong — it worked, it just quietly capped how many bugs I was going to find, and I didn't realize that was the cost until I'd already paid it.&lt;/p&gt;

&lt;h2&gt;
  
  
  📼 Watch It Live
&lt;/h2&gt;

&lt;p&gt;Full video walkthrough: &lt;a href="https://youtu.be/Hg3GoT8XJr0" rel="noopener noreferrer"&gt;youtu.be/Hg3GoT8XJr0&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Plus six ~30-second recorded terminal demos (one per format) and the full test-suite-and-fuzz-run, captured for real, not staged:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flrjlhyv84qge9y0kpcr7.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flrjlhyv84qge9y0kpcr7.gif" alt="Terminal recording of the full cargo test suite passing and a live differential fuzz run against the vendored Python reference, ending with zero divergences" width="800" height="699"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The other six — WAV, AIFF, FLAC, MP3, Ogg, MP4 — are in &lt;a href="https://github.com/GauravS13/tinytag-rs/tree/main/public/demo" rel="noopener noreferrer"&gt;public/demo/&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  📊 All the Numbers in One Place
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;177/177&lt;/strong&gt; tests passing, traced 1:1 from upstream's own test data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;9,549 cases, 65 seconds, 0 divergences&lt;/strong&gt; on the last differential fuzz run&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;34&lt;/strong&gt; documented architectural decisions (&lt;a href="https://github.com/GauravS13/tinytag-rs/blob/main/DECISIONS.md" rel="noopener noreferrer"&gt;DECISIONS.md&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;0&lt;/strong&gt; &lt;code&gt;unsafe&lt;/code&gt; blocks, &lt;strong&gt;0&lt;/strong&gt; dependencies&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;3&lt;/strong&gt; real bugs found in the original, reproduced faithfully&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;12&lt;/strong&gt; bugs the fuzzer found in this port during development, all fixed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;1.65x&lt;/strong&gt; average speedup, honestly measured, honestly reported&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every decision, including the ones that were wrong on the first attempt, is in &lt;a href="https://github.com/GauravS13/tinytag-rs/blob/main/DECISIONS.md" rel="noopener noreferrer"&gt;DECISIONS.md&lt;/a&gt; — 34 of them, not a highlight reel.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔧 Go Poke at It Yourself
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/GauravS13/tinytag-rs.git
&lt;span class="nb"&gt;cd &lt;/span&gt;tinytag-rs
cargo &lt;span class="nb"&gt;test&lt;/span&gt;                                              &lt;span class="c"&gt;# 177 tests, traced 1:1 from upstream&lt;/span&gt;
cargo build &lt;span class="nt"&gt;--release&lt;/span&gt; &lt;span class="nt"&gt;--bin&lt;/span&gt; fuzz_harness &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; ./target/release/fuzz_harness 65   &lt;span class="c"&gt;# run the fuzz yourself&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Full source, tests, DECISIONS.md, and the fuzz/bench harnesses: &lt;a href="https://github.com/GauravS13/tinytag-rs" rel="noopener noreferrer"&gt;github.com/GauravS13/tinytag-rs&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;Submission by Siddhivinayk for &lt;a href="https://coderesurrection.com/2026/" rel="noopener noreferrer"&gt;Port Mortem / Code Resurrection 2026&lt;/a&gt;, Track D (Python → Rust).Tagging &lt;a class="mentioned-user" href="https://dev.to/partnerships_raptors"&gt;@partnerships_raptors&lt;/a&gt; &lt;/p&gt;

</description>
      <category>hackathonraptors</category>
      <category>portmortem</category>
      <category>python</category>
      <category>rust</category>
    </item>
  </channel>
</rss>
