fix(xo-vmdk-to-vhd/grabTables): read each entry independently (#5255)

Reading all entries at once cause problems on some VMDKs (those generated by VirtualBox) because they appear to be distributed throughout the VMDK thus making the buffer not fit in memory.

See https://xcp-ng.org/forum/topic/3374/cannot-import-ova-from-virtualbox/14?_=1599689219209
This commit is contained in:
Nicolas Raynaud 2020-09-16 11:46:10 +02:00 committed by GitHub
parent 4264e34ffd
commit 14b8cda543
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 18 deletions

View File

@ -16,6 +16,8 @@
> Users must be able to say: “I had this issue, happy to know it's fixed”
- [Import VMDK] Fix `No position specified for vmdisk1` error (PR [#5255](https://github.com/vatesfr/xen-orchestra/pull/5255))
### Packages to release
> Packages will be released in the order they are here, therefore, they should
@ -33,4 +35,5 @@
>
> In case of conflict, the highest (lowest in previous list) `$version` wins.
- xo-vmdk-to-vhd patch
- xo-web minor

View File

@ -50,28 +50,14 @@ async function grabTables(
fileAccessor
) {
const cachedGrainTables = []
let grainTableAddresMin = Infinity
let grainTableAddressMax = -Infinity
for (let i = 0; i < grainDirectoryEntries; i++) {
const grainTableAddr = grainDir[i] * SECTOR_SIZE
if (grainTableAddr !== 0) {
grainTableAddresMin = Math.min(grainTableAddresMin, grainTableAddr)
grainTableAddressMax = Math.max(
grainTableAddressMax,
grainTableAddr + grainTablePhysicalSize
)
}
}
const grainTableBuffer = await fileAccessor(
grainTableAddresMin,
grainTableAddressMax
)
for (let i = 0; i < grainDirectoryEntries; i++) {
const grainTableAddr = grainDir[i] * SECTOR_SIZE
if (grainTableAddr !== 0) {
const addr = grainTableAddr - grainTableAddresMin
cachedGrainTables[i] = new Uint32Array(
grainTableBuffer.slice(addr, addr + grainTablePhysicalSize)
await fileAccessor(
grainTableAddr,
grainTableAddr + grainTablePhysicalSize
)
)
}
}