Skip to content

Commit ceca39a

Browse files
committed
fix: add handling for incorrect position
1 parent 3dcaed6 commit ceca39a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

@xen-orchestra/fs/src/azure.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,14 @@ export default class AzureHandler extends RemoteHandlerAbstract {
251251
if (typeof file !== 'string') {
252252
file = file.fd
253253
}
254-
const blobClient = this.#containerClient.getBlobClient(file)
255254
try {
256-
const downloadResponse = await blobClient.download(position, buffer.length)
255+
const blobClient = this.#containerClient.getBlobClient(file)
256+
const blobSize = (await blobClient.getProperties()).contentLength
257+
if (position >= blobSize) {
258+
throw new Error(`Requested range starts beyond blob size: ${blobSize}`)
259+
}
260+
261+
const downloadResponse = await blobClient.download(position, Math.min(blobSize - position, buffer.length))
257262
const bytesRead = await this.#streamToBuffer(downloadResponse.readableStreamBody, buffer)
258263
return { bytesRead, buffer }
259264
} catch (e) {

0 commit comments

Comments
 (0)