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 select_support_mcl::init_fast #3

Merged
merged 1 commit into from
Jan 21, 2021
Merged

Fix select_support_mcl::init_fast #3

merged 1 commit into from
Jan 21, 2021

Conversation

jltsiren
Copy link

select_support_mcl::init_fast would sometimes crash because the initialization tried to access the padding after the bitvector (see simongog#402). This PR fixes the issue.

In the example, pos_of_last_arg_in_the_block is 25587424, which is greater than the length of the bitvector (25587416).

The relevant part of the code is here: https://github.com/simongog/sdsl-lite/blob/c32874cb2d8524119f25f3b501526fe692df29f4/include/sdsl/select_support_mcl.hpp#L287-L308

  • On line 287, args_in_the_word() may find nonexistent args in the padding, at least for select_support_mcl<0, 0>.
  • That could bring the number of args in the last superblock past another multiple of 64, passing the test on line 288.
  • In that case, we store the position of a nonexistent arg in array arg_position on line 289.
  • If the next multiple of 64 would start another superblock, we have a full superblock and pass the test on line 293.
  • On line 295, we take the the nonexistent position we stored in arg_position as a candidate for pos_of_last_arg_in_the_block.
  • We don't find further candidates, because the loop on line 297 tests for ii < v->size().
  • If the last superblock happens to be long, we pass the test on line 303.
  • The loop on line 307 iterates over the superblock, up to and including pos_of_last_arg_in_the_block.
  • We access each position in the superblock on line 308, which ultimately causes the assertion failure.

We can fix this by adding cnt_new = std::min(cnt_new, m_arg_cnt); after line 287.

@jltsiren jltsiren merged commit 454f0f4 into master Jan 21, 2021
@jltsiren jltsiren deleted the fix-init-fast branch January 21, 2021 02:28
@tsnorri
Copy link

tsnorri commented Feb 11, 2021

If using GPL is not something that is particularly important, would you consider patching the development version of SDSL, too? It uses the revised BSD licence.

@jltsiren
Copy link
Author

I got the impression that the development version has also been abandoned.

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