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

Reader::findMetadataStart runs forever on faulty files #42

Closed
eteubert opened this issue Aug 11, 2016 · 3 comments
Closed

Reader::findMetadataStart runs forever on faulty files #42

eteubert opened this issue Aug 11, 2016 · 3 comments

Comments

@eteubert
Copy link

If the database file is faulty, findMetadataStart has to go through the whole file byte by byte, which is extremely slow and creates a timeout exception (for servers with default config of 30 seconds timeout).

I know I can (and probably should) check for the validity of the database file before using the reader. However, it would be nice if it could handle that case more gracefully.

@oschwald
Copy link
Member

Per the MaxMind DB spec, the metadata will always be in the last 128 KB. We should probably just stop searching at that point.

@eteubert
Copy link
Author

I am still hoping for a patch :)

Is it as simple as changing the outer search loop?

// from this
for ($i = 0; $i < $fileSize - $markerLength + 1; $i++) {

// ... to this?
for ($i = 0; $i < 128000 + 1; $i++) {

@oschwald
Copy link
Member

You'd want the minimum the current number and 128k as a file could be less than 128k.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants