feat(vhd-lib/peekFooterFromStream): check checksum and content
This commit is contained in:
parent
ad5691dcb2
commit
a5afe0bca1
@ -36,7 +36,7 @@
|
||||
<!--packages-start-->
|
||||
|
||||
- @xen-orchestra/self-signed patch
|
||||
- vhd-lib patch
|
||||
- vhd-lib minor
|
||||
- @xen-orchestra/fs patch
|
||||
- vhd-cli patch
|
||||
- xo-vmdk-to-vhd minor
|
||||
|
@ -3,11 +3,10 @@
|
||||
const { readChunk } = require('@vates/read-chunk')
|
||||
|
||||
const { FOOTER_SIZE } = require('./_constants')
|
||||
const { fuFooter } = require('./_structs')
|
||||
const { unpackFooter } = require('./Vhd/_utils.js')
|
||||
|
||||
module.exports = async function peekFooterFromStream(stream) {
|
||||
const footerBuffer = await readChunk(stream, FOOTER_SIZE)
|
||||
const footer = fuFooter.unpack(footerBuffer)
|
||||
stream.unshift(footerBuffer)
|
||||
return footer
|
||||
const buffer = await readChunk(stream, FOOTER_SIZE)
|
||||
stream.unshift(buffer)
|
||||
return unpackFooter(buffer)
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import { defer } from 'golike-defer'
|
||||
import { format, JsonRpcError } from 'json-rpc-peer'
|
||||
import { noSuchObject } from 'xo-common/api-errors.js'
|
||||
import { pipeline } from 'stream'
|
||||
import { checkFooter, peekFooterFromVhdStream } from 'vhd-lib'
|
||||
import { peekFooterFromVhdStream } from 'vhd-lib'
|
||||
import { vmdkToVhd } from 'xo-vmdk-to-vhd'
|
||||
|
||||
import { VDI_FORMAT_VHD, VDI_FORMAT_RAW } from '../xapi/index.mjs'
|
||||
@ -192,14 +192,12 @@ async function handleImport(req, res, { type, name, description, vmdkData, srId,
|
||||
break
|
||||
case 'vhd':
|
||||
{
|
||||
const footer = await peekFooterFromVhdStream(vhdStream)
|
||||
try {
|
||||
checkFooter(footer)
|
||||
} catch (e) {
|
||||
const footer = await peekFooterFromVhdStream(vhdStream).catch(e => {
|
||||
if (e instanceof assert.AssertionError) {
|
||||
throw new JsonRpcError(`Vhd file had an invalid header ${e}`)
|
||||
}
|
||||
}
|
||||
throw e
|
||||
})
|
||||
vhdStream = part
|
||||
size = footer.currentSize
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user