Skip to content

Conversation

lenzo-ka
Copy link
Contributor

Description

Fixes a null pointer dereference when reading malformed or empty ARPA language model files.

The NGRAM_ARPA case in ngram_model_read did not check if the model was NULL before proceeding, unlike other file type cases. This caused a crash in ngram_model_apply_weights when processing invalid files.

Changes:

  • Added null check after ngram_model_trie_read_arpa call
  • Returns NULL immediately if model read fails, consistent with other cases

Verification steps

  • Compiled successfully with no errors
  • Prevents NULL pointer dereference crash reported in the issue
  • Matches existing error handling pattern used in NGRAM_BIN case

Fixes #432

Replace unsafe %s format specifier with %c%c%c%c to prevent
reading past the 4-byte non-null-terminated id buffer.

Fixes #431
Add null check for NGRAM_ARPA case to prevent crash when
reading malformed or empty language model files.

Fixes #432
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Missing null check in ngram_model_read for NGRAM_ARPA

1 participant