|
| 1 | +Backported from distribution/distribution upstream: |
| 2 | +https://github.com/distribution/distribution/commit/521ea3d973cb0c7089ebbcdd4ccadc34be941f54 |
| 3 | + |
| 4 | +Modified to apply to vendored code by: corvus-callidus <108946721+corvus-callidus@users.noreply.github.com> |
| 5 | + - Adjusted paths |
| 6 | + - Removed references to files which are not present in the vendored code |
| 7 | + |
| 8 | + |
| 9 | +From 521ea3d973cb0c7089ebbcdd4ccadc34be941f54 Mon Sep 17 00:00:00 2001 |
| 10 | +From: "Jose D. Gomez R" <jose.gomez@suse.com> |
| 11 | +Date: Mon, 24 Apr 2023 18:52:27 +0200 |
| 12 | +Subject: [PATCH] Fix runaway allocation on /v2/_catalog |
| 13 | +MIME-Version: 1.0 |
| 14 | +Content-Type: text/plain; charset=UTF-8 |
| 15 | +Content-Transfer-Encoding: 8bit |
| 16 | + |
| 17 | +Introduced a Catalog entry in the configuration struct. With it, |
| 18 | +it's possible to control the maximum amount of entries returned |
| 19 | +by /v2/catalog (`GetCatalog` in registry/handlers/catalog.go). |
| 20 | + |
| 21 | +It's set to a default value of 1000. |
| 22 | + |
| 23 | +`GetCatalog` returns 100 entries by default if no `n` is |
| 24 | +provided. When provided it will be validated to be between `0` |
| 25 | +and `MaxEntries` defined in Configuration. When `n` is outside |
| 26 | +the aforementioned boundary, ErrorCodePaginationNumberInvalid is |
| 27 | +returned. |
| 28 | + |
| 29 | +`GetCatalog` now handles `n=0` gracefully with an empty response |
| 30 | +as well. |
| 31 | + |
| 32 | +Signed-off-by: José D. Gómez R. <1josegomezr@gmail.com> |
| 33 | +Co-authored-by: Cory Snider <corhere@gmail.com> |
| 34 | +--- |
| 35 | + vendor/github.com/docker/distribution/registry/api/v2/descriptors.go | 17 ++ |
| 36 | + vendor/github.com/docker/distribution/registry/api/v2/errors.go | 9 + |
| 37 | + 2 files changed, 26 insertions(+) |
| 38 | + |
| 39 | +diff --git a/vendor/github.com/docker/distribution/registry/api/v2/descriptors.go b/vendor/github.com/docker/distribution/registry/api/v2/descriptors.go |
| 40 | +index a9616c58ad..c3bf90f71d 100644 |
| 41 | +--- a/vendor/github.com/docker/distribution/registry/api/v2/descriptors.go |
| 42 | ++++ b/vendor/github.com/docker/distribution/registry/api/v2/descriptors.go |
| 43 | +@@ -134,6 +134,19 @@ var ( |
| 44 | + }, |
| 45 | + } |
| 46 | + |
| 47 | ++ invalidPaginationResponseDescriptor = ResponseDescriptor{ |
| 48 | ++ Name: "Invalid pagination number", |
| 49 | ++ Description: "The received parameter n was invalid in some way, as described by the error code. The client should resolve the issue and retry the request.", |
| 50 | ++ StatusCode: http.StatusBadRequest, |
| 51 | ++ Body: BodyDescriptor{ |
| 52 | ++ ContentType: "application/json", |
| 53 | ++ Format: errorsBody, |
| 54 | ++ }, |
| 55 | ++ ErrorCodes: []errcode.ErrorCode{ |
| 56 | ++ ErrorCodePaginationNumberInvalid, |
| 57 | ++ }, |
| 58 | ++ } |
| 59 | ++ |
| 60 | + repositoryNotFoundResponseDescriptor = ResponseDescriptor{ |
| 61 | + Name: "No Such Repository Error", |
| 62 | + StatusCode: http.StatusNotFound, |
| 63 | +@@ -490,6 +503,7 @@ var routeDescriptors = []RouteDescriptor{ |
| 64 | + }, |
| 65 | + }, |
| 66 | + Failures: []ResponseDescriptor{ |
| 67 | ++ invalidPaginationResponseDescriptor, |
| 68 | + unauthorizedResponseDescriptor, |
| 69 | + repositoryNotFoundResponseDescriptor, |
| 70 | + deniedResponseDescriptor, |
| 71 | +@@ -1578,6 +1592,9 @@ var routeDescriptors = []RouteDescriptor{ |
| 72 | + }, |
| 73 | + }, |
| 74 | + }, |
| 75 | ++ Failures: []ResponseDescriptor{ |
| 76 | ++ invalidPaginationResponseDescriptor, |
| 77 | ++ }, |
| 78 | + }, |
| 79 | + }, |
| 80 | + }, |
| 81 | +diff --git a/vendor/github.com/docker/distribution/registry/api/v2/errors.go b/vendor/github.com/docker/distribution/registry/api/v2/errors.go |
| 82 | +index 97d6923aa0..87e9f3c14b 100644 |
| 83 | +--- a/vendor/github.com/docker/distribution/registry/api/v2/errors.go |
| 84 | ++++ b/vendor/github.com/docker/distribution/registry/api/v2/errors.go |
| 85 | +@@ -133,4 +133,13 @@ var ( |
| 86 | + longer proceed.`, |
| 87 | + HTTPStatusCode: http.StatusNotFound, |
| 88 | + }) |
| 89 | ++ |
| 90 | ++ ErrorCodePaginationNumberInvalid = errcode.Register(errGroup, errcode.ErrorDescriptor{ |
| 91 | ++ Value: "PAGINATION_NUMBER_INVALID", |
| 92 | ++ Message: "invalid number of results requested", |
| 93 | ++ Description: `Returned when the "n" parameter (number of results |
| 94 | ++ to return) is not an integer, "n" is negative or "n" is bigger than |
| 95 | ++ the maximum allowed.`, |
| 96 | ++ HTTPStatusCode: http.StatusBadRequest, |
| 97 | ++ }) |
| 98 | + ) |
0 commit comments