Skip to content

Always use buf in CopyBuffer#144

Merged
tonistiigi merged 1 commit intotonistiigi:masterfrom
jedevc:copy-buffer-fix
Jan 5, 2023
Merged

Always use buf in CopyBuffer#144
tonistiigi merged 1 commit intotonistiigi:masterfrom
jedevc:copy-buffer-fix

Conversation

@jedevc
Copy link
Copy Markdown
Collaborator

@jedevc jedevc commented Jan 4, 2023

CopyBuffer may not always use the provided buffer, in the case that the src implements WriterTo. So, in the case that the io.ReadCloser returned by fs.Open implements this method, the packet size limit will not be enforced, creating an oversized packet that results in an error on the receiver.

To avoid this, we can create an anonymous structure to wrap the src, which prevents the shortcut taken by the standard library.

I'm not 100% sure of the approach for this, maybe we should write our own Copy method to circumvent this issue instead?

cc @crazy-max

CopyBuffer may not always use the provided buffer, in the case that the
src implements WriterTo. So, in the case that the io.ReadCloser returned
by fs.Open implements this method, the packet size limit will not be
enforced, creating an oversized packet that results in an error on the
receiver.

To avoid this, we can create an anonymous structure to wrap the src,
which prevents the shortcut taken by the standard library.

Signed-off-by: Justin Chadwell <me@jedevc.com>
@jedevc
Copy link
Copy Markdown
Collaborator Author

jedevc commented Jan 5, 2023

@tonistiigi suggested adding a for loop with an io.LimitReader instead of the hacky workaround here.

@tonistiigi tonistiigi merged commit fb43384 into tonistiigi:master Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants