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

[BUG]: NullReferenceException thrown using IConnection.GetRaw() for JSON content in Octokit 8.0.1 #2789

Closed
1 task done
martincostello opened this issue Oct 2, 2023 · 4 comments · Fixed by #2791
Closed
1 task done
Labels
Type: Bug Something isn't working as documented

Comments

@martincostello
Copy link
Contributor

What happened?

Calling IConnection.GetRaw() for an endpoint that responds with non-binary content (e.g. application/json) results in a NullReferenceException being thrown when updating to Octokit 8.0.1.

This appears to be due to the changes in #2782 to handle large binary responses.

In the case where the response is not a Stream but instead is just a string, response.Body as Stream returns null, and then causes an exception here:

await stream.CopyToAsync(ms);

Fix incoming shortly, but a workaround is to use IConnection.GetRawStream() and refactor calling code to deal with Stream instead of byte[].

Versions

8.0.1

Relevant log output

System.NullReferenceException: Object reference not set to an instance of an object.
    at Octokit.Connection.StreamToByteArray(Stream stream) in /_/Octokit/Http/Connection.cs:line 724
    at Octokit.Connection.GetRaw(IRequest request) in /_/Octokit/Http/Connection.cs:line 704
    at MartinCostello.Costellobot.Pages.DeliveryModel.OnGet(Int64 id) in /_/src/Costellobot/Pages/Webhooks/Delivery.cshtml.cs:line 64

Code of Conduct

  • I agree to follow this project's Code of Conduct
@martincostello martincostello added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Oct 2, 2023
@github-project-automation github-project-automation bot moved this to 🆕 Triage in 🧰 Octokit Active Oct 2, 2023
@martincostello
Copy link
Contributor Author

martincostello added a commit to martincostello/costellobot that referenced this issue Oct 2, 2023
Use `IConnection.GetRawStream()` instead of `IConnection.GetRaw()` to improve the code and also work around octokit/octokit.net#2789.
@martincostello
Copy link
Contributor Author

Also affects IRepositoryContentsClient.GetRawContent(), but in that case I can't workaround it myself.

costellobot bot pushed a commit to martincostello/costellobot that referenced this issue Oct 2, 2023
* Bump Octokit from 8.0.0 to 8.0.1

Bumps [Octokit](https://github.com/octokit/octokit.net) from 8.0.0 to 8.0.1.
- [Release notes](https://github.com/octokit/octokit.net/releases)
- [Changelog](https://github.com/octokit/octokit.net/blob/main/docs/releases.md)
- [Commits](octokit/octokit.net@v8.0.0...v8.0.1)

---
updated-dependencies:
- dependency-name: Octokit
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Use IConnection.GetRawStream()

Use `IConnection.GetRawStream()` instead of `IConnection.GetRaw()` to improve the code and also work around octokit/octokit.net#2789.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: martincostello <martin@martincostello.com>
@nickfloyd nickfloyd removed the Status: Triage This is being looked at and prioritized label Oct 3, 2023
@nickfloyd
Copy link
Contributor

Hey @martincostello great catch. 🤦 This one is on me, I reviewed it and let it through and completely missed the implementations that you mentioned above.

I'll have a look at IRepositoryContentsClient.GetRawContent() and see what I can come up with. As always, thank you for doing all that you do here, and apologies for the trouble.

@nickfloyd nickfloyd moved this from 🆕 Triage to 🏗 In progress in 🧰 Octokit Active Oct 3, 2023
@martincostello
Copy link
Contributor Author

No problem! I did push up a fix in #2791 but I fat-fingered the number into the other fix for GitVersion and it got closed when you merged it 🤦🏻‍♂️

kfcampbell added a commit that referenced this issue Nov 7, 2023
* Fix handling for Streams

Fix `NullReferenceException` if raw content was handled as a string rather than a stream by `HttpClientAdapter.BuildResponse()`.
Resolves #2789.

* Add Connection.GetRaw tests

Add tests for `Connection.GetRaw()` and for #2789.

---------

Co-authored-by: Keegan Campbell <me@kfcampbell.com>
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in 🧰 Octokit Active Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants