Skip to content

Commit 5913195

Browse files
committed
Verify the hash after copying patches
1 parent 1ad734d commit 5913195

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/commands/patch/handle-patch.mts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,24 @@ async function processFilePatch(
323323
let result = true
324324
try {
325325
await fs.copyFile(blobPath, filepath)
326-
logger.success(`Patch applied successfully`)
326+
327+
// Verify the hash after copying to ensure file integrity.
328+
const verifyHashResult = await computeSHA256(filepath)
329+
if (!verifyHashResult.ok) {
330+
logger.error(
331+
`Failed to verify hash after patch: ${verifyHashResult.cause || verifyHashResult.message}`,
332+
)
333+
result = false
334+
} else if (verifyHashResult.data !== fileInfo.afterHash) {
335+
logger.error(`Hash verification failed after patch`)
336+
logger.group()
337+
logger.log(`Expected: ${fileInfo.afterHash}`)
338+
logger.log(`Got: ${verifyHashResult.data}`)
339+
logger.groupEnd()
340+
result = false
341+
} else {
342+
logger.success(`Patch applied successfully`)
343+
}
327344
} catch (e) {
328345
logger.error('Error applying patch')
329346
debugDir('error', e)

0 commit comments

Comments
 (0)