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 fieldset.New bug when prefix slice has len < cap #2851

Merged
merged 2 commits into from
Dec 3, 2023

Conversation

sivukhin
Copy link
Contributor

@sivukhin sivukhin commented Dec 3, 2023

Accidentally inspected gqlgen source code and found a bug in FieldSet.New implementation which can be reproduced if prefix slice is "not full" (length < capacity). In this case internal function parseUnnestedKeyFieldSet will overwrite same slice element multiple times - which will lead to incorrect FieldSet construction.

Bug fix is pretty simple: we should set max capacity equal to length in parseUnnestedKeyFieldSet (using extended slicing operation x[start:end:cap])

In order to cover this bug 1 test case were added: TestWithPrefix/prefix with len<capacity

From the brief source code search it looks like no code were exposed to this bug because prefix argument always passed as nil. But, as this is public library interface, someone can use this logic.

If it's possible - than removal of this argument can be considered (with potential breaking changes).

I have:

  • Added tests covering the bug / feature (see testing)

@coveralls
Copy link

coveralls commented Dec 3, 2023

Coverage Status

coverage: 79.357% (+3.5%) from 75.856%
when pulling 70d31c2 on sivukhin:fix-fieldset-bug
into cb3c1c8 on 99designs:master.

@StevenACoffman StevenACoffman merged commit 5e98a16 into 99designs:master Dec 3, 2023
17 of 18 checks passed
@StevenACoffman
Copy link
Collaborator

Thanks! There are a lot of things in the ecosystem that use gqlgen as a library: https://github.com/99designs/gqlgen-contrib so these kind of fixes are always welcome!

Yeah, this argument is mostly a leftover that we didn't want to break compatibility by removing. It's probably worth moving to an alternative and deprecating this for a few versions.

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.

3 participants