tafia / quick-protobuf

A rust implementation of protobuf parser
MIT License
452 stars 87 forks source link

Self-referential fields cause stack overflow #118

Closed jimblandy closed 6 years ago

jimblandy commented 6 years ago

When I compile the following with pb-rs, I get a stack overflow:

/* -*- Mode: protobuf; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * vim: set ts=8 sts=4 et sw=4 tw=99: */

syntax = "proto2";

message ViaOneOf {
    oneof Alternatives {
        Data present = 1;
        bool absent  = 2;
    }

    message Data {
        required ViaOneOf self_reference = 1;
    }
}

message ViaOptional {
    optional Data data = 1;

    message Data {
        required ViaOptional self_reference = 1;
    }
}

Either definition alone is sufficient. The error is:

$ pb-rs Recursive.proto
Found 2 messages, and 0 enums
Writing message ViaOneOf

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Aborted (core dumped)
$ 

Google's protoc accepts both without complaint.

Such structures are actually used in Firefox heap snapshots.

tafia commented 6 years ago

Thanks for the issue, it is weird that it was not catched in existing tests. Anyway I have just made a PR to fix it (#119), do you mind trying it before I merge? (Else I'll do it tomorrow).

(note that it successfully parses Coredump.proto file too).