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

Infinite loop when parsing bdb table #37

Open
daveharmon opened this issue Mar 17, 2023 · 14 comments
Open

Infinite loop when parsing bdb table #37

daveharmon opened this issue Mar 17, 2023 · 14 comments

Comments

@daveharmon
Copy link

At https://github.com/knqyf263/go-rpmdb/blob/master/pkg/bdb/hash_page.go#L70

I believe this continue statement without any changes to the loop variables is causing an infinite loop for some types of corrupted bdb databases.

I am able to pretty consistently recreate this issue, though I am unable to give you an example at this time.

Adding "currentPageNo = currentPage.NextPageNo`" breaks the loop and causes this library to detect the corruption, though I'm not totally sure if that's the right solution. Please let me know.

@daveharmon
Copy link
Author

It seems like the pages that are entering this if-statement are just fully zero'd-out, so their page type is 0

@daveharmon
Copy link
Author

I would appreciate it if someone could ack this issue and say if they plan to take a look or if this is likely to linger until more consumers +1 it

@knqyf263
Copy link
Owner

Contributions welcome

@michaelvolovik
Copy link

Hello
Seems that we have a fix for this issue.
Will it be possible to create PR for approval and merge?

@knqyf263
Copy link
Owner

Sure

@rhdesmond
Copy link

We are seeing this issue and investigating

@rhdesmond
Copy link

rhdesmond commented Aug 28, 2023

Shouldn't this be part of the loop post statement? Otherwise the line mentioned by @daveharmon will cause an infinite loop.

Alternatively, we can break out of the loop when we see that the page isn't an overflow page (e.g. it's a new page, so we are done parsing the overflow page?), but I'm not 100% sure of the semantics here.

@rhdesmond
Copy link

Seems like Jfrog has forked the library with a timeout fix: https://github.com/jfrog/go-rpmdb

@knqyf263
Copy link
Owner

I need a contribution.

@rjammala
Copy link

rjammala commented Dec 5, 2023

@knqyf263 can you please accept the fix?

@knqyf263
Copy link
Owner

knqyf263 commented Dec 6, 2023

Honestly, I don't think adding timeout is ideal. We should detect the infinite loop somehow.

@rhdesmond
Copy link

rhdesmond commented Dec 6, 2023

The infinite loop is when it hits the currentPage.PageType != OverflowPageType condition, then continues without updating the loop variable or erroring out.

The reason I did not modify the hash table parsing is I don't know if this is expected behavior. If you think it's incorrect db file, we can just error when it hits

if currentPage.PageType != OverflowPageType { continue }

and change the continue to

return nil, xerrors.Errorf("Invalid page encountered when parsing hash page")

@rhdesmond
Copy link

rhdesmond commented Dec 6, 2023

The other option is to add the loop update clause to before the continue statement:

if currentPage.PageType != OverflowPageType {
  currentPageNo = currentPage.NextPageNo
  continue
}

@knqyf263
Copy link
Owner

@wagoodman Do you know something about it?
84f408f

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

No branches or pull requests

5 participants