octokit / octokit.net

A GitHub API client library for .NET
https://octokitnet.readthedocs.io/en/latest/
MIT License
2.62k stars 1.07k forks source link

[BUG]: Int32 overflow for Github object ids #2893

Open Apolloluy opened 2 months ago

Apolloluy commented 2 months ago

What happened?

Running

var envs = await github.Repository.Environment.GetAll(owner, "API_CICD");

Returns image

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) image

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

jeffhandley commented 2 months ago

Since this seems to repro using 10.0.0, it must be separate from https://github.com/octokit/octokit.net/issues/2889, which was fixed with https://github.com/octokit/octokit.net/pull/2890.

kartheekp-ms commented 6 days ago

Upgrading the octokit package version to 11.0.1 fixed the issue for me. https://www.nuget.org/packages/Octokit/11.0.1

martincostello commented 16 hours ago

I can still repro this with 11.0.1 for deployment environments. I have one with an ID of 2296494046 which overflows the Id property as it's still an int:

https://github.com/octokit/octokit.net/blob/615dee9c30c88ee73754baeb3f113f97834a7aeb/Octokit/Models/Response/DeploymentEnvironment.cs#L28-L31

martincostello commented 14 hours ago

I would do a PR to fix it, but fixing it properly is a lottttttttt of breaking changes.