Skip to content

Conversation

michiel-dewilde
Copy link

The qsieve_factor() function uses a temporary file (with name qs_inf->fname) for internal operation.

There were a few issues with this file:

  • The name is supposed to be random, yet a prior srand() call ensures that different threads will be using an identical "random" name. The ensuing race condition leads to crashes.
  • The pre-existence of another file with the same name is not verified.
  • The file is created in the current directory instead of some temporary space.

Fix: resorting to standard temporary file approaches (mkstemp on POSIX and GetTempFileName on Windows).

The `qsieve_factor()` function uses a temporary file (with name `qs_inf->fname`)
for internal operation.

There were a few issues with this file:

* The name is supposed to be random, yet a prior `srand()` call ensures
  that different threads will be using an identical "random" name.
  The ensuing race condition leads to crashes.
* The pre-existence of another file with the same name is not verified.
* The file is created in the current directory instead of some temporary space.

Fix: resorting to standard temporary file approaches
(`mkstemp` on POSIX and `GetTempFileName` on Windows).
@fredrik-johansson
Copy link
Collaborator

Looks like a reasonable fix.

@wbhart is there a reason why the quadratic sieve uses files in the first place instead of doing everything in memory?

@wbhart
Copy link
Collaborator

wbhart commented Jan 2, 2023

No, not really, apart from the fact that you don't know how much memory there is.

Pari/GP used to use files and I just adopted the same technique. Bill Allombert subsequently switched it to using memory, which is defensible these days.

@fredrik-johansson
Copy link
Collaborator

Indeed, #708 mentions this.

Anyway, I will merge this as soon as CI is working again.

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.

3 participants