mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-23 03:06:38 +00:00
fix(usbboot): Limit usbboot transfers to 1MiB
Change-type: patch
This commit is contained in:
parent
2158772e3b
commit
7fb382bee0
@ -30,6 +30,8 @@ const usb = require('./usb')
|
|||||||
const NULL_BUFFER_SIZE = 0
|
const NULL_BUFFER_SIZE = 0
|
||||||
const NULL_BUFFER = Buffer.alloc(NULL_BUFFER_SIZE)
|
const NULL_BUFFER = Buffer.alloc(NULL_BUFFER_SIZE)
|
||||||
|
|
||||||
|
const ONE_MEGABYTE = 1048576
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @summary The size of the boot message bootcode length section
|
* @summary The size of the boot message bootcode length section
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
@ -206,6 +208,12 @@ exports.sendBufferSize = (device, size) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const chunks = function *(buffer, size) {
|
||||||
|
for (let start = 0; start < buffer.length; start += size) {
|
||||||
|
yield buffer.slice(start, start + size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @summary Write a buffer to an OUT endpoint
|
* @summary Write a buffer to an OUT endpoint
|
||||||
* @function
|
* @function
|
||||||
@ -231,9 +239,11 @@ exports.write = (device, endpoint, buffer) => {
|
|||||||
.delay(USB_REQUEST_DELAY_MS)
|
.delay(USB_REQUEST_DELAY_MS)
|
||||||
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return Bluebird.fromCallback((callback) => {
|
endpoint.timeout = USB_BULK_TRANSFER_TIMEOUT_MS
|
||||||
endpoint.timeout = USB_BULK_TRANSFER_TIMEOUT_MS
|
return Bluebird.each(chunks(buffer, ONE_MEGABYTE), (chunk) => {
|
||||||
endpoint.transfer(buffer, callback)
|
return Bluebird.fromCallback((callback) => {
|
||||||
|
endpoint.transfer(chunk, callback)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user