feat(vhd-lib/peekFooterFromStream): check checksum and content

This commit is contained in:
Julien Fontanet 2022-05-29 14:07:48 +02:00
parent ad5691dcb2
commit a5afe0bca1
3 changed files with 9 additions and 12 deletions

View File

@ -36,7 +36,7 @@
<!--packages-start--> <!--packages-start-->
- @xen-orchestra/self-signed patch - @xen-orchestra/self-signed patch
- vhd-lib patch - vhd-lib minor
- @xen-orchestra/fs patch - @xen-orchestra/fs patch
- vhd-cli patch - vhd-cli patch
- xo-vmdk-to-vhd minor - xo-vmdk-to-vhd minor

View File

@ -3,11 +3,10 @@
const { readChunk } = require('@vates/read-chunk') const { readChunk } = require('@vates/read-chunk')
const { FOOTER_SIZE } = require('./_constants') const { FOOTER_SIZE } = require('./_constants')
const { fuFooter } = require('./_structs') const { unpackFooter } = require('./Vhd/_utils.js')
module.exports = async function peekFooterFromStream(stream) { module.exports = async function peekFooterFromStream(stream) {
const footerBuffer = await readChunk(stream, FOOTER_SIZE) const buffer = await readChunk(stream, FOOTER_SIZE)
const footer = fuFooter.unpack(footerBuffer) stream.unshift(buffer)
stream.unshift(footerBuffer) return unpackFooter(buffer)
return footer
} }

View File

@ -6,7 +6,7 @@ import { defer } from 'golike-defer'
import { format, JsonRpcError } from 'json-rpc-peer' import { format, JsonRpcError } from 'json-rpc-peer'
import { noSuchObject } from 'xo-common/api-errors.js' import { noSuchObject } from 'xo-common/api-errors.js'
import { pipeline } from 'stream' import { pipeline } from 'stream'
import { checkFooter, peekFooterFromVhdStream } from 'vhd-lib' import { peekFooterFromVhdStream } from 'vhd-lib'
import { vmdkToVhd } from 'xo-vmdk-to-vhd' import { vmdkToVhd } from 'xo-vmdk-to-vhd'
import { VDI_FORMAT_VHD, VDI_FORMAT_RAW } from '../xapi/index.mjs' 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 break
case 'vhd': case 'vhd':
{ {
const footer = await peekFooterFromVhdStream(vhdStream) const footer = await peekFooterFromVhdStream(vhdStream).catch(e => {
try {
checkFooter(footer)
} catch (e) {
if (e instanceof assert.AssertionError) { if (e instanceof assert.AssertionError) {
throw new JsonRpcError(`Vhd file had an invalid header ${e}`) throw new JsonRpcError(`Vhd file had an invalid header ${e}`)
} }
} throw e
})
vhdStream = part vhdStream = part
size = footer.currentSize size = footer.currentSize
} }