sassoftware / relic

Relic is a service and a tool for adding digital signatures to operating system packages for Linux and Windows
Apache License 2.0
153 stars 41 forks source link

Fix stream reading in comdoc #19

Closed chrisroberts closed 1 year ago

chrisroberts commented 1 year ago

This PR resolves the issue described in #17. When reading a stream and a partial sector read is required, if that read is at the end of the file it will result in an io.EOF error. That error will be returned immediately with only the bytes read prior to the sector read. The io.EOF tells the reader there is no more data which can cause unexpected errors (like the missed writing n bytes in the case of archive/tar ).

To resolve this, when reading the partial sector an error is only returned if it's not an io.EOF error. If the file read reaches EOF, it can be ignored so the data read from the sector can be copied into whatever space remains in the buffer and the rest can stored for the next read. If the buffer has space for all the data from the sector, then the next call will result in an io.EOF as remaining will be zero at that point.

mtharp commented 1 year ago

Closing in favor of the fix discussed in #17. Thanks again for your help!