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

JVM Crash When ID Doesn't Exist #28

Closed
iprovalo opened this issue Jan 14, 2023 · 4 comments
Closed

JVM Crash When ID Doesn't Exist #28

iprovalo opened this issue Jan 14, 2023 · 4 comments
Assignees

Comments

@iprovalo
Copy link

    @Test
    public void testJvmCrashLoad() {
        Assert.assertEquals(null, sp.idToPiece(38067));
    }

This test will crash jvm.

@levyfan
Copy link
Owner

levyfan commented Jan 16, 2023

This is caused by the sentence piece native code const std::string &piece = spp->IdToPiece(id);. Please check their issues track.

@levyfan
Copy link
Owner

levyfan commented Jan 16, 2023

I think there is a clear warning that id should be valid.

  // Returns the string representation of vocab with `id`.
  // id must be 0 <= id < GetPieceSize().
  virtual const std::string &IdToPiece(int id) const {
    return model_proto_->pieces(id).piece();
  }

https://github.com/google/sentencepiece/blob/02555b8f1994cd05e4c22e3c4fe55220134e518a/src/model_interface.h#L137

@levyfan
Copy link
Owner

levyfan commented Jan 16, 2023

I add a size check to avoid JVM crash here #29, now it will throw an exception that you can catch.

@levyfan levyfan self-assigned this Jan 16, 2023
@levyfan levyfan closed this as completed Jan 16, 2023
@iprovalo
Copy link
Author

thank you very much, @levyfan !

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

2 participants