Skip to content

Protobuf parser state handling wrong for implicit close (END_OBJECT) #598

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

Open
cowtowncoder opened this issue May 31, 2025 · 1 comment
Open

Comments

@cowtowncoder
Copy link
Member

When ProtobufParser reaches end of input at top level, it will both:

  1. Report JsonToken.END_OBJECT to close root level implicit Object value
  2. Call JsonParser.close() to close input

While this works in many ways (current token properly set; further JsonParser.nextToken() calls will return null), it will not work wrt FasterXML/jackson-core#1438 .
Ideally we would probably add one more state (STATE_ROOT_END?) to cover this case.

@cowtowncoder
Copy link
Member Author

Places to change in ProtobufParser:

    @Override
    public JsonToken nextToken() throws IOException {
        ...
// 591:
        case STATE_ROOT_KEY:
            // end-of-input?
            if (_inputPtr >= _inputEnd) {
                if (!loadMore()) {
                    close();
                    return _updateToken(JsonToken.END_OBJECT);
                }
           ....
// 689:
        case STATE_MESSAGE_END: // occurs if we end with array
            close(); // sets state to STATE_CLOSED
            return _updateToken(JsonToken.END_OBJECT);
         ...
    }

    private JsonToken _skipUnknownField(int tag, int wireType) throws IOException
    {
// 961:
            if (_state == STATE_NESTED_KEY) {
                if (_inputPtr >= _inputEnd) {
                    loadMoreGuaranteed();
                }
            } else if (_inputPtr >= _inputEnd) {
                if (!loadMore()) {
                    close();
                    return _updateToken(JsonToken.END_OBJECT);
                }
            }

// 1022
    @Override
    public boolean nextFieldName(SerializableString sstr) throws IOException
    {
        if (_state == STATE_ROOT_KEY) {
            if (_inputPtr >= _inputEnd) {
                if (!loadMore()) {
                    close();
                    _updateToken(JsonToken.END_OBJECT);
                    return false;
                }
            }
// 1103:
    @Override
    public String nextFieldName() throws IOException
    {
        if (_state == STATE_ROOT_KEY) {
            if (_inputPtr >= _inputEnd) {
                if (!loadMore()) {
                    close();
                    _updateToken(JsonToken.END_OBJECT);
                    return null;
                }
            }


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

No branches or pull requests

1 participant