I am in awe of BrowserUK's (and your) willngness to tackle this as a challenge.
May I humbly offer a simpler suggestion? Do you have control of the file-generator's output? Can you -- by accepting a somewhat larger datafile -- align your data on 512-byte boundaries with padding? Then, the frame is always recognizable and there's room for an individual frame to grow or shrink a bit.