Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix assertion fail #10638

Merged
merged 1 commit into from
May 16, 2019
Merged

Fix assertion fail #10638

merged 1 commit into from
May 16, 2019

Conversation

Chocobo1
Copy link
Member

When fileSize == 0, the second index could be smaller than the first index, thus trigger the
assert check in IndexInterval constructor.

Closes #10611.

Will backport to v4_1_x.

@Chocobo1 Chocobo1 added the Core label May 13, 2019
@Chocobo1 Chocobo1 added this to the 4.2.0 milestone May 13, 2019
@Chocobo1 Chocobo1 changed the title Fix invalid piece range generated Fix invalid piece range May 13, 2019
@Chocobo1 Chocobo1 force-pushed the idxRange branch 2 times, most recently from fa0ad50 to e391a69 Compare May 14, 2019 03:03

const int begin = static_cast<int>(fileOffset / pieceLength());
const int end = (fileSize > 0) ? static_cast<int>((fileOffset + fileSize - 1) / pieceLength())
: begin;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait... If file has size of 0 then it has no pieces, isn't it? So you need to return some kind of invalid PieceRange. Or am I wrong?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tested, for a file with fileSize == 0, fileOffset is 0.
so I think it should still return valid PieceRange.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tested, for a file with fileSize == 0, fileOffset is 0.

But it still has no pieces, isn't it? If you return [0; 0] range it means the file has 1 piece. Seems incorrect to me...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this part, these code are convoluted...

Copy link
Member

@glassez glassez May 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but you didn't fix zero-sized files. It still here.
Apparently, the problem is a little more complicated than it seems...

Nevermind. I was confused by the jumble of IndexInterval and IndexRange in this code.

@Chocobo1 Chocobo1 force-pushed the idxRange branch 2 times, most recently from 490617a to 9dd6136 Compare May 14, 2019 06:13
@Chocobo1 Chocobo1 changed the title Fix invalid piece range Fix assertion fail May 14, 2019
@Chocobo1 Chocobo1 force-pushed the idxRange branch 2 times, most recently from 2108a66 to 55e8ca6 Compare May 14, 2019 06:20
src/base/bittorrent/torrentinfo.cpp Outdated Show resolved Hide resolved
When fileSize == 0, the second index could be smaller than the first index,
thus trigger the assert check in IndexInterval constructor.

Closes qbittorrent#10611.
@Chocobo1 Chocobo1 merged commit c9ff0ab into qbittorrent:master May 16, 2019
@Chocobo1 Chocobo1 deleted the idxRange branch May 16, 2019 02:39
@Chocobo1 Chocobo1 mentioned this pull request May 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ASSERT: "first <= last" in file src/base/indexrange.h, line 45
2 participants