octokit.net: [BUG]: Int32 overflow for Github object ids
What happened?
Running
var envs = await github.Repository.Environment.GetAll(owner, "API_CICD");
Returns
System.OverflowException: 'Value was either too large or too small for an Int32.'
When attempting to parse the Github.id field in the response.
Versions
Octokit.nupkg 10.0.0 (.net)
Relevant log output
System.OverflowException
HResult=0x80131516
Message=Value was either too large or too small for an Int32.
Source=System.Private.CoreLib
StackTrace:
at System.Convert.ThrowInt32OverflowException()
Value = 2398648970
{
"id": 2398648970,
"node_id": "EN_kwDOJhYfOc6O-HqK",
"name": "test",
"url": "https://api.github.com/repos/ContextureHIE/API_CICD/environments/test",
"html_url": "https://github.com/ContextureHIE/API_CICD/deployments/activity_log?environments_filter=test",
"created_at": "2024-03-01T22:23:36Z",
"updated_at": "2024-03-01T22:23:36Z",
"can_admins_bypass": true,
"protection_rules": [
{
"id": 16441898,
"node_id": "GA_kwDOJhYfOc4A-uIq",
"type": "required_reviewers",
"prevent_self_review": false,
"reviewers": [
{
"type": "User",
"reviewer": {
"login": "Apolloluy",
"id": 44653204,
"node_id": "MDQ6VXNlcjQ0NjUzMjA0",
"avatar_url": "https://avatars.githubusercontent.com/u/44653204?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Apolloluy",
"html_url": "https://github.com/Apolloluy",
"followers_url": "https://api.github.com/users/Apolloluy/followers",
"following_url": "https://api.github.com/users/Apolloluy/following{/other_user}",
"gists_url": "https://api.github.com/users/Apolloluy/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Apolloluy/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Apolloluy/subscriptions",
"organizations_url": "https://api.github.com/users/Apolloluy/orgs",
"repos_url": "https://api.github.com/users/Apolloluy/repos",
"events_url": "https://api.github.com/users/Apolloluy/events{/privacy}",
"received_events_url": "https://api.github.com/users/Apolloluy/received_events",
"type": "User",
"site_admin": false
}
}
]
}
],
"deployment_branch_policy": null
}
Code of Conduct
- I agree to follow this project’s Code of Conduct
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 32 (23 by maintainers)
Commits related to this issue
- update package versions — committed to NuGet/Entropy by kartheekp-ms 3 years ago
Thanks for the catch @martincostello & @jessehouwing - not sure how I missed it but I did, thanks for helping to round out the corners on this. I’m going to put the PR back into draft, do another sweep to make sure I catch what you found and possibly others and then open it back up for a review.
Apologies for the delay and thanks again for the follow up ❤
Just a quick follow up. I have found about 68 OpenAPI components that should have an Int64 formatter but do not. This means that there is a possibility that there are 68 endpoints used octokit.net that need their corresponding objects updated from
inttolong. I am working on putting together that list now.As an aside, @kfcampbell and I are working on a few ways to prevent this from happening in the future. Apologies again for all of the trouble here.
Hey @martincostello it turns out that we had a lot more of these than first thought due to commit id / comment id being so prolific.
I’m working on a release (breaking change) this morning for the others.
I would do a PR to fix it, but fixing it properly is a lottttttttt of breaking changes.
Thanks @0x5bfa! It does. The backing API sometimes uses the strict Id when dealing with the resource itself (these are typically of type int64|long|bigint - like with the issues API for instance, but will use the scoped id named number to refer to a resource that is contained within another resource - as in repo/issues, int32 | int
I’m trying to track and parse out which should be which and ensure that their types are accurate and they are named appropriately. Given the one @joscol found It’s prompted me to review the entire SDK to ensure it is doing what it should.
The PR should be good to go now… this should hopefully cover all areas above.
Just an FYI: I found the flaw in my analysis scripts. I was only looking at migrations - where ids shifted from
int32toint64I completely left out the base structure SQL - the initialization of the database itself 🤦🏼♂️️I was able to find a few more and will be updating those as well:
This will make for a pretty big change set but I feel that’s better than introducing more (smaller) major releases for this effort - that feels like it would create extra noise and confusion given things would still be broken until they were all shipped complete.
This #2941 should cover the remaining fields that were defined as
int- that needed to belong.We have determine that the following resources from the GitHub REST API are at risk of overflow issues. Some have been addressed, we’ll need to see if there are other APIs/representations in octokit.net that need to be changed as well.
Yeah I just verified. It looks like we are missing the format attribute for that OpenAPI definition. I’m going to see if I can get an idea of how many are out of sync with the backing data.
I think the move forward here is to:
We could use a hammer and just update all of the id’s to longs 😬️ but that has the potential to cause heaps of issues when we could be much more surgical here.
I’m going to start tracking down all of this and will come back with a more solid plan/execution.
Apologies for all of the trouble everyone. We’ll get this cleaned up; thank you for the patience.
@nickfloyd No worries. The repo isn’t public so I can’t link to it directly, but this is the relevant line:
Yeah, it’s now a general issue with the library. Various resources have gone past
int.MaxValuefor their IDs and now can’t be interacted with if the request/response uses an ID bigger than that.The fix would be simple, change all the
ints tolongs for anything representing an ID, but it’s a hugely breaking change (would need to be a v12) and touches a lot of the code (when I did a quick look the other week, IIRC it would touch hundreds of files).There’d only be any point doing such changing if the team would accept such a change, as otherwise it’d be a waste of people’s effort.
I still getting the error on version
11.0.1When i callor