fix incorrect MTP xact_len calculation #3284
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe the PR
Fixes the calculation of remaining bytes to transfer in MTP device class.
The original code casts the result of subtraction into
uint16_tbefore taking the minimum, which will break all transfers with more than 65535 bytes. Only(filesize & 0xFFFF)bytes can be transferred before the transfer comes to a halt. This PR has deferred the cast touint16_tafter calculating the transfer size inuint32_tdomain.This bug is discovered when I'm testing MTP Device with an LittleFS on SPI flash as the backing store, with about 11MiB of free space I copied a lot more data than what was available in the examples and it immediately revealed this issue. After applying this change, the issue was resolved and I can copy megabytes of files into the responder device.
And file hashes are compared. The file was copied to the responder device on macOS and is copied out from responder device on Windows.
Additional context
The test project can be found at https://github.com/RigoLigoRLC/esp32s3-tusb-mtp . It uses my own fork of espressif/tinyusb with MTP implementation applied on top of v0.18 branch.