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

Fix invalid iterator access in TimeInterpolatableBuffer #5138

Merged

Conversation

virtuald
Copy link
Member

Found using a fuzzer. I ran this fix for several hundred thousand executions without any errors.

@virtuald virtuald requested a review from a team as a code owner February 26, 2023 07:42
@virtuald
Copy link
Member Author

In case anyone cares, here's the fuzz driver I wrote:

static constexpr units::second_t kBufferDuration = 1.5_s;

int main(int argc, char **argv) {

    frc::TimeInterpolatableBuffer<int> buffer(kBufferDuration, [](const int& start, const int &end, double t) {
        return 4;
    });

    std::ifstream t(argv[1]);
    std::stringstream fb;
    fb << t.rdbuf();
    auto str = fb.str();
    auto *buf = str.c_str();
    auto end = str.size();

    int i = 0;
    double ts;

    while (i < str.size()) {
        auto c = buf[i];
        i += 1;
        switch (((int)c) % 2) {
        case 0:
            // sample some timestamp (needs time)
            if (i + 8 >= end) {
                return 0;
            }

            ts = *(double*)(buf + i);
            buffer.Sample(units::time::second_t(ts));
            i += 8;
            break;
        case 1:
            // add some sample (needs time, sample)
            if (i + 8 >= end) {
                return 0;
            }

            ts = *(double*)(buf + i);
            buffer.AddSample(units::time::second_t(ts), 0);

            i += 8;
            break;
        }
    }
}

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
@PeterJohnson PeterJohnson merged commit e5c4c6b into wpilibsuite:main Feb 27, 2023
@virtuald virtuald deleted the fix-time-interpolatable-buffer branch February 27, 2023 04:34
Starlight220 pushed a commit to Starlight220/allwpilib that referenced this pull request Mar 2, 2023
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

Successfully merging this pull request may close these issues.

None yet

3 participants