Skip to content

[Bug]: Images committed with Git LFS show as broken images in pull request descriptions #35445

Closed

Description

@GuardedAirplane

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. In a github.com pull request description, embed an image tracked by Git LFS. For example, this public file (the repository tracks *.png with LFS):
    ![](https://github.com/IDEDARY/Bevypunk/blob/HEAD/art/movies/intro_frames/1_background.png?raw=true)
  2. 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 the gh token 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 @ 2482b03

Environment

github.com; any client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions