fix: unwrap binary data in COW adapter to fix blob integrity check (v5.7.5)

CRITICAL BUG FIX #2 - VFS "Blob integrity check failed" errors

Root cause (Workshop team finding): COWStorageAdapter wraps binary data in JSON
{_binary: true, data: "base64..."} but doesn't unwrap on read, causing hash
mismatch.

Timeline:
- WRITE: BlobStorage hashes original content → stored hash
- Storage adapter wraps in JSON before saving
- READ: Adapter returns JSON wrapper as Buffer
- BlobStorage hashes JSON wrapper → different hash → ERROR

Fix (baseStorage.ts:332-336):
- Detect {_binary: true, data: "..."} objects
- Unwrap and decode base64 back to original Buffer
- BlobStorage now hashes same data on read and write

This completes v5.7.5 with TWO critical VFS fixes:
1. Compression race condition (BlobStorage async init)
2. JSON wrapper hash mismatch (COW adapter unwrapping)

Credit: Workshop team for forensic analysis of blob corruption

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
David Snelling 2025-11-12 16:01:25 -08:00
parent 55ba3a2044
commit 201fbed78c

View file

@ -329,6 +329,11 @@ export abstract class BaseStorage extends BaseStorageAdapter {
if (Buffer.isBuffer(data)) {
return data
}
// v5.7.5: Unwrap binary data stored as {_binary: true, data: "base64..."}
// Fixes "Blob integrity check failed" - hash must be calculated on original content
if (data._binary && typeof data.data === 'string') {
return Buffer.from(data.data, 'base64')
}
return Buffer.from(JSON.stringify(data))
} catch (error) {
return undefined