[Bug]: Images committed with Git LFS show as broken images in pull request descriptions
Before submitting
- [x] I searched existing issues and did not find a duplicate.
- [x] I included enough detail to reproduce or investigate the problem.
Area
apps/server
Steps to reproduce
- In a github.com pull request description, embed an image tracked by Git LFS. For example, this public file (the repository tracks
*.pngwith LFS): - Open the pull request in the pull request panel.
Expected behavior
The image renders, as it does on GitHub.
Actual behavior
A broken image. gitHubMediaUrl maps blob/…?raw=true to raw.githubusercontent.com, which returns the LFS pointer, not the file:
$ curl -sS -w '%{http_code} %{content_type} %{size_download}\n' \
https://raw.githubusercontent.com/IDEDARY/Bevypunk/HEAD/art/movies/intro_frames/1_background.png
version https://git-lfs.github.com/spec/v1
oid sha256:5a8f16132efe3eb67a8dea335571beac2745147010dabcedde78dbe708e6bccd
size 38688
200 text/plain; charset=utf-8 130
sourceControlMediaResponse serves those 130 bytes as image/png, the type of the file name, so the image fails to decode. The Contents API returns the pointer too, so GitHub Enterprise Server files read through it (#35439) have the same gap.
Two routes return the real file:
https://media.githubusercontent.com/media/<owner>/<repo>/<ref>/<path>with the token. github.com only, and it returns 404 for a file that is not in LFS.- The Git LFS batch API,
POST https://<host>/<owner>/<repo>.git/info/lfs/objects/batch, which every GitHub host serves. It accepts theghtoken with Basic or Bearer auth.
A tested fix is ready on a branch: when a repository file reads back as a pointer (at most 1024 bytes and starting with the spec line), the server asks the batch API for the object and streams it. For the file above it returns the 38,688-byte PNG whose SHA-256 matches the pointer's oid.
Impact
Minor bug or occasional failure
Version or commit
main @ 2482b03a01
Environment
github.com; any client.