fix: prevent panic when GitLab release has more links than sources#36295
fix: prevent panic when GitLab release has more links than sources#36295wxiaoguang merged 4 commits intogo-gitea:mainfrom
Conversation
…n sources The code incorrectly assumed rel.Assets.Links and rel.Assets.Sources arrays have equal length. This causes index out of bounds panic when migrating GitLab releases with more links than sources, which is common with GoReleaser-generated releases. The fix sets ContentType to nil instead of using Sources[k].Format. This is safe because ContentType is not actually used when uploading release assets - the repo_model.Attachment struct has no ContentType field, so the value was being discarded anyway. Fixes go-gitea#36292 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
services/migrations/gitlab.go
Outdated
| ID: int64(asset.ID), | ||
| Name: asset.Name, | ||
| ContentType: &rel.Assets.Sources[k].Format, | ||
| ContentType: nil, // GitLab Links don't provide content type |
There was a problem hiding this comment.
GitLab never provides the content type? Or it just sometimes doesn't provide the content type?
Any document?
There was a problem hiding this comment.
It does for Sources but not for Links. The thing is that the content type is not used at all later in the flow (as far as Claude could find at least) and hence there is no reason for setting it.
There was a problem hiding this comment.
If it's sure that "content type is not used", is it better to completely remove this field? From the ReleaseAsset struct?
There was a problem hiding this comment.
I can agree on that. Would you like me to do that change in this PR or as a followup PR?
There was a problem hiding this comment.
I think it's better to take the best approach in one PR as long as we found one.
There was a problem hiding this comment.
Pushed another commit
There was a problem hiding this comment.
Since the field has been removed, the test is not needed anymore.
I added some comments for the removal. If we need the content type in the future, the tests should be redesigned.
The ContentType field was never used during release asset upload since repo_model.Attachment has no ContentType field. Remove it from the struct and all migration downloaders. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…o-gitea#36295) The code incorrectly assumed rel.Assets.Links and rel.Assets.Sources arrays have equal length. This causes index out of bounds panic when migrating GitLab releases with more links than sources, which is common with GoReleaser-generated releases. Fixes go-gitea#36292 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* giteaofficial/main: fix: generate IDs for HTML headings without id attribute (go-gitea#36233) Add 'allow_maintainer_edit' API option for creating a pull request (go-gitea#36283) fix: prevent panic when GitLab release has more links than sources (go-gitea#36295)
It is unfortunately all mixed up, because refreshing the data, means breaking the tests. And changing the code means needing fresh data. - tests: ignore some more headers and sort the rest when dumping http responses - code: fixed #10234 by requesting the latest issues first. - tests: created a new repo to replace the disappeared repo, needed for the skip-numbers test - refreshed the testdata. - follow-up fixes to get the tests green. - including a cherry-pick of go-gitea/gitea#36295 and #11272 Co-authored-by: Joakim Olsson <joakim@unbound.se> Co-authored-by: Robert Wolff <mahlzahn@posteo.de> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11282 Reviewed-by: Robert Wolff <mahlzahn@posteo.de> Reviewed-by: Gusted <gusted@noreply.codeberg.org> Reviewed-by: patdyn <patdyn@noreply.codeberg.org> Co-authored-by: oliverpool <git@olivier.pfad.fr> Co-committed-by: oliverpool <git@olivier.pfad.fr>
It is unfortunately all mixed up, because refreshing the data, means breaking the tests. And changing the code means needing fresh data. - tests: ignore some more headers and sort the rest when dumping http responses - code: fixed #10234 by requesting the latest issues first. - tests: created a new repo to replace the disappeared repo, needed for the skip-numbers test - refreshed the testdata. - follow-up fixes to get the tests green. - including a cherry-pick of go-gitea/gitea#36295 and #11272 Co-authored-by: Joakim Olsson <joakim@unbound.se> Co-authored-by: Robert Wolff <mahlzahn@posteo.de> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11282 Reviewed-by: Robert Wolff <mahlzahn@posteo.de> Reviewed-by: Gusted <gusted@noreply.codeberg.org> Reviewed-by: patdyn <patdyn@noreply.codeberg.org> Co-authored-by: oliverpool <git@olivier.pfad.fr> Co-committed-by: oliverpool <git@olivier.pfad.fr> (cherry picked from commit a0d6970)
… (#11484) **Backport:** https://codeberg.org/forgejo/forgejo/pulls/11282 It is unfortunately all mixed up, because refreshing the data, means breaking the tests. And changing the code means needing fresh data. - tests: ignore some more headers and sort the rest when dumping http responses - code: fixed #10234 by requesting the latest issues first. - tests: created a new repo to replace the disappeared repo, needed for the skip-numbers test - refreshed the testdata. - follow-up fixes to get the tests green. - including a cherry-pick of go-gitea/gitea#36295 and #11272 Co-authored-by: oliverpool <git@olivier.pfad.fr> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11484 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Reviewed-by: Robert Wolff <mahlzahn@posteo.de> Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [go-gitea/gitea](https://github.com/go-gitea/gitea) | patch | `1.25.3` -> `1.25.4` | --- ### Release Notes <details> <summary>go-gitea/gitea (go-gitea/gitea)</summary> ### [`v1.25.4`](https://github.com/go-gitea/gitea/releases/tag/v1.25.4) [Compare Source](go-gitea/gitea@v1.25.3...v1.25.4) - SECURITY - Release attachments must belong to the intended repo ([#​36347](go-gitea/gitea#36347)) ([#​36375](go-gitea/gitea#36375)) - Fix permission check on org project operations ([#​36318](go-gitea/gitea#36318)) ([#​36373](go-gitea/gitea#36373)) - Clean watches when make a repository private and check permission when send release emails ([#​36319](go-gitea/gitea#36319)) ([#​36370](go-gitea/gitea#36370)) - Add more check for stopwatch read or list ([#​36340](go-gitea/gitea#36340)) ([#​36368](go-gitea/gitea#36368)) - Fix openid setting check ([#​36346](go-gitea/gitea#36346)) ([#​36361](go-gitea/gitea#36361)) - Fix cancel auto merge bug ([#​36341](go-gitea/gitea#36341)) ([#​36356](go-gitea/gitea#36356)) - Fix delete attachment check ([#​36320](go-gitea/gitea#36320)) ([#​36355](go-gitea/gitea#36355)) - LFS locks must belong to the intended repo ([#​36344](go-gitea/gitea#36344)) ([#​36349](go-gitea/gitea#36349)) - Fix bug on notification read ([#​36339](go-gitea/gitea#36339)) [#​36387](go-gitea/gitea#36387) - ENHANCEMENTS - Add more routes to the "expensive" list ([#​36290](go-gitea/gitea#36290)) - Make "commit statuses" API accept slashes in "ref" ([#​36264](go-gitea/gitea#36264)) ([#​36275](go-gitea/gitea#36275)) - BUGFIXES - Fix markdown newline handling during IME composition ([#​36421](go-gitea/gitea#36421)) [#​36424](go-gitea/gitea#36424) - Fix missing repository id when migrating release attachments ([#​36389](go-gitea/gitea#36389)) - Fix bug when compare in the pull request ([#​36363](go-gitea/gitea#36363)) ([#​36372](go-gitea/gitea#36372)) - Fix incorrect text content detection ([#​36364](go-gitea/gitea#36364)) ([#​36369](go-gitea/gitea#36369)) - Fill missing `has_code` in repository api ([#​36338](go-gitea/gitea#36338)) ([#​36359](go-gitea/gitea#36359)) - Fix notifications pagination query parameters ([#​36351](go-gitea/gitea#36351)) ([#​36358](go-gitea/gitea#36358)) - Fix some trivial problems ([#​36336](go-gitea/gitea#36336)) ([#​36337](go-gitea/gitea#36337)) - Prevent panic when GitLab release has more links than sources ([#​36295](go-gitea/gitea#36295)) ([#​36305](go-gitea/gitea#36305)) - Fix stats bug when syncing release ([#​36285](go-gitea/gitea#36285)) ([#​36294](go-gitea/gitea#36294)) - Always honor user's choice for "delete branch after merge" ([#​36281](go-gitea/gitea#36281)) ([#​36286](go-gitea/gitea#36286)) - Use the requested host for LFS links ([#​36242](go-gitea/gitea#36242)) ([#​36258](go-gitea/gitea#36258)) - Fix panic when get editor config file ([#​36241](go-gitea/gitea#36241)) ([#​36247](go-gitea/gitea#36247)) - Fix regression in writing authorized principals ([#​36213](go-gitea/gitea#36213)) ([#​36218](go-gitea/gitea#36218)) - Fix WebAuthn error checking ([#​36219](go-gitea/gitea#36219)) ([#​36235](go-gitea/gitea#36235)) Instances on **[Gitea Cloud](https://cloud.gitea.com)** will be automatically upgraded to this version during the specified maintenance window. </details> --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xOC4xIiwidXBkYXRlZEluVmVyIjoiNDEuMTguMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsia2luZC9kZXBlbmRlbmN5Il19--> Reviewed-on: https://gitea.com/gitea/helm-gitea/pulls/1012 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Renovate Bot <renovate-bot@gitea.com> Co-committed-by: Renovate Bot <renovate-bot@gitea.com>
The code incorrectly assumed rel.Assets.Links and rel.Assets.Sources arrays have equal length. This causes index out of bounds panic when migrating GitLab releases with more links than sources, which is common with GoReleaser-generated releases.
The fix sets ContentType to nil instead of using Sources[k].Format. This is safe because ContentType is not actually used when uploading release assets - the repo_model.Attachment struct has no ContentType field, so the value was being discarded anyway.
Fixes #36292