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 CLStream memcpy read 1 extra byte #240

Merged
merged 2 commits into from
Sep 16, 2024

Conversation

xiaokang
Copy link

@xiaokang xiaokang commented Sep 15, 2024

It should only copy the length passed from argument, instead of length + 1, which may cause ASAN global-buffer-overflow.

    void init(const void *_value, int32_t _length, bool copyData = true) override {
        const size_t length = _length;
        this->pos = 0;
        if (copyData) {
            T *tmp = (T *) this->value;
            if (tmp == NULL || !this->ownValue) {
                tmp = _CL_NEWARRAY(T, length + 1);
                this->buffer_size = length;
            } else if (length > this->buffer_size || length < (this->buffer_size / 2)) {//expand, or shrink
                tmp = (T *) realloc(tmp, sizeof(T) * (length + 1));
                this->buffer_size = length;
            }
            memcpy(tmp, _value, length + 1);  ///////////////// THIS IS THE BUGGY LINE  //////////
            this->value = tmp;
        } else {
            if (ownValue && this->value != NULL) {
                _CLDELETE_LARRAY((T *) this->value);
            }
            this->value = (T *)_value;
            this->buffer_size = 0;
        }
        this->m_size = length;
        this->ownValue = copyData;
    };

@xiaokang xiaokang merged commit 5e9566a into apache:clucene Sep 16, 2024
3 of 4 checks passed
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.

2 participants