-
Notifications
You must be signed in to change notification settings - Fork 765
fix buffer overwrite issue #1418
Conversation
|
@jim3ma Thanks for your contribution. 🍻 |
Signed-off-by: 楚贤 <[email protected]>
3d7783a to
92903d3
Compare
| _, err := io.Copy(writer, piece.RawContent(noWrapper)) | ||
| if piece.autoReset { | ||
| piece.ResetContent() | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can not ResetContent here in writePieceToFile.
Because the same piece may be used in target writer queue after write finish in client writer queue.
https://github.com/dragonflyoss/Dragonfly/blob/master/dfget/core/downloader/p2p_downloader/client_writer.go#L223
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when enable cross write, we will read piece content twice? but this is a buffer, it has index, when read twice, I think we need reset some index, #1411 is a good workaround.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have rewritten the fix code #1411 , could you help me review whether it can work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!
|
IMOP, the pull request #1411 is an appropriate solution. I think that we can work on it to make it better. |
Ⅰ. Describe what this PR did
RawContent func returns a buffer io, when enable autoReset, the buffer io can be reused by AcquireBufferSize, so, if first piece is processed slow than an other, the faster piece will overwrite buffer.
Ⅱ. Does this pull request fix one issue?
fix #1415
Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)
N/A
Ⅳ. Describe how to verify it
N/A
Ⅴ. Special notes for reviews