-
Notifications
You must be signed in to change notification settings - Fork 12.2k
perplexity : fix integer overflow #9783
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
Conversation
3229586
to
22cc760
Compare
examples/perplexity/perplexity.cpp
Outdated
int64_t n_vocab; | ||
int64_t n_chunk; | ||
in.read((char *)&n_vocab, sizeof(n_vocab)); | ||
in.read((char *)&n_chunk, sizeof(n_chunk)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using int64_t
here is for n_chunk
was incorrect. Pushing a fix
for (int i = 0; i < (int) batch.n_tokens; i += n_batch) { | ||
const int n_tokens = std::min<int>(n_batch, batch.n_tokens - i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC the C standard only guarantees at least 16 bit for int
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Wikpedia:
The standard integer size is platform-dependent. In C, it is denoted by int and required to be at least 16 bits. Windows and Unix systems have 32-bit ints on both 32-bit and 64-bit architectures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to cppreference:
int — basic integer type. The keyword int may be omitted if any of the modifiers listed below are used. If no length modifiers are present, it's guaranteed to have a width of at least 16 bits. However, on 32/64 bit systems it is almost exclusively guaranteed to have width of at least 32 bits (see below).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt this is a concern. We can safely assume that int
will always be 32-bit
* perplexity : fix integer overflow ggml-ci * perplexity : keep n_vocab as int and make appropriate casts ggml-ci
* perplexity : fix integer overflow ggml-ci * perplexity : keep n_vocab as int and make appropriate casts ggml-ci
* perplexity : fix integer overflow ggml-ci * perplexity : keep n_vocab as int and make appropriate casts ggml-ci
fix #9779
There was an integer overflow in
i*n_vocab
: