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 memory allocation bug in bigm_gin.c. #23

Merged
merged 1 commit into from
Feb 25, 2025

Conversation

MasaoFujii
Copy link
Member

Previously, pg_bigm allocated only a single byte (sizeof(bool)) for extra_data, an output argument used to pass additional data from gin_extract_query_bigm() to gin_bigm_consistent() and gin_bigm_triconsistent(). However, extra_data must be allocated as an array with a pointer for each key. This misallocation could lead to a segmentation fault.

This commit fixes the issue by ensuring gin_extract_query_bigm() properly allocates memory for the required number of key pointers in extra_data.

Reported-by: Robert Pang
Reported-by: howladr
Discussion: #9

Previously, pg_bigm allocated only a single byte (sizeof(bool)) for extra_data,
an output argument used to pass additional data from gin_extract_query_bigm()
to gin_bigm_consistent() and gin_bigm_triconsistent().
However, extra_data must be allocated as an array with a pointer for each key.
This misallocation could lead to a segmentation fault.

This commit fixes the issue by ensuring gin_extract_query_bigm() properly
allocates memory for the required number of key pointers in extra_data.

Reported-by: Robert Pang
Reported-by: howladr
@MasahikoSawada
Copy link
Contributor

Thank you for creating a PR to fix this issue. The fix looks good to me.

@MasaoFujii MasaoFujii merged commit 0aeefb1 into pgbigm:master Feb 25, 2025
MasaoFujii added a commit that referenced this pull request Feb 25, 2025
Previously, pg_bigm allocated only a single byte (sizeof(bool)) for extra_data,
an output argument used to pass additional data from gin_extract_query_bigm()
to gin_bigm_consistent() and gin_bigm_triconsistent().
However, extra_data must be allocated as an array with a pointer for each key.
This misallocation could lead to a segmentation fault.

This commit fixes the issue by ensuring gin_extract_query_bigm() properly
allocates memory for the required number of key pointers in extra_data.

Back-patch to pg_bigm 1.0 where this bug exists.

Reported-by: Robert Pang (@robert-pang)
Reported-by: howladr (@howladr)
Reviewed-by: Robert Pang (@robert-pang)
Reviewed-by: howladr (@howladr)
Reviewed-by: Masahiko Sawada (@MasahikoSawada)
MasaoFujii added a commit that referenced this pull request Feb 25, 2025
Previously, pg_bigm allocated only a single byte (sizeof(bool)) for extra_data,
an output argument used to pass additional data from gin_extract_query_bigm()
to gin_bigm_consistent() and gin_bigm_triconsistent().
However, extra_data must be allocated as an array with a pointer for each key.
This misallocation could lead to a segmentation fault.

This commit fixes the issue by ensuring gin_extract_query_bigm() properly
allocates memory for the required number of key pointers in extra_data.

Back-patch to pg_bigm 1.0 where this bug exists.

Reported-by: Robert Pang (@robert-pang)
Reported-by: howladr (@howladr)
Reviewed-by: Robert Pang (@robert-pang)
Reviewed-by: howladr (@howladr)
Reviewed-by: Masahiko Sawada (@MasahikoSawada)
MasaoFujii added a commit that referenced this pull request Feb 25, 2025
Previously, pg_bigm allocated only a single byte (sizeof(bool)) for extra_data,
an output argument used to pass additional data from gin_extract_query_bigm()
to gin_bigm_consistent() and gin_bigm_triconsistent().
However, extra_data must be allocated as an array with a pointer for each key.
This misallocation could lead to a segmentation fault.

This commit fixes the issue by ensuring gin_extract_query_bigm() properly
allocates memory for the required number of key pointers in extra_data.

Back-patch to pg_bigm 1.0 where this bug exists.

Reported-by: Robert Pang (@robert-pang)
Reported-by: howladr (@howladr)
Reviewed-by: Robert Pang (@robert-pang)
Reviewed-by: howladr (@howladr)
Reviewed-by: Masahiko Sawada (@MasahikoSawada)
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