Skip to content

Conversation

@jdroenner
Copy link
Member

@jdroenner jdroenner commented Aug 14, 2023

  • I added an entry to CHANGELOG.md if knowledge of this change could be valuable to users.

Here is a brief summary of what I did:

  • This PR changes the QueryRectangle struct to combine a temporal and a spatial query.

  • All QueryRectangles are now created using a static constructor method.

  • VectorQueryRectangle use the same components as before just different composition.

  • RasterQueryRectangle now use a GridBounds in Pixels.

  • Projection might still have a 1Px offset issue:
    Peek 2024-04-16 14-09

  • TODO: Tests

  • TODO: Re-Grid-Operator

michaelmattig and others added 28 commits November 24, 2025 19:48
- [ ] I added an entry to [`CHANGELOG.md`](CHANGELOG.md) if knowledge of
this change could be valuable to users.

---

Here is a brief summary of what I did:

<TEXT>
- [ ] I added an entry to [`CHANGELOG.md`](CHANGELOG.md) if knowledge of
this change could be valuable to users.

---

Here is a brief summary of what I did:

<TEXT>
…longer works now that resolutions are no longer part of the query rectangle
- [ ] I added an entry to [`CHANGELOG.md`](CHANGELOG.md) if knowledge of
this change could be valuable to users.

---

Here is a brief summary of what I did:

<TEXT>
…ks now that resolutions are no longer part of the query rectangle (#1112)

- [ ] I added an entry to [`CHANGELOG.md`](CHANGELOG.md) if knowledge of
this change could be valuable to users.

---

Here is a brief summary of what I did:

<TEXT>
…e/geoengine into new-pixel-based-queries-rebase
- [ ] I added an entry to [`CHANGELOG.md`](CHANGELOG.md) if knowledge of
this change could be valuable to users.

---

Here is a brief summary of what I did:

<TEXT>
@jdroenner jdroenner changed the title pixel based query rects for raster requests feat: pixel based query rects for raster requests Jan 30, 2026
call_on_generic_raster_processor!(
processor,
p =>
raster_stream_to_png_bytes(p, query_rect, query_ctx, request.width, request.height, request.time.map(Into::into), raster_colorizer.map(Into::into), conn_closed).await
).map_err(error::Error::from)
raster_stream_to_png_bytes(p, query_rect, query_ctx, request.width, request.height, request.time.map(Into::into), Some(raster_colorizer), conn_closed).await // TODO: pass raster colorizer here

Check failure

Code scanning / CodeQL

Uncontrolled allocation size High

This allocation size is derived from a
user-provided value
and could allocate arbitrary amounts of memory.
This allocation size is derived from a
user-provided value
and could allocate arbitrary amounts of memory.
This allocation size is derived from a
user-provided value
and could allocate arbitrary amounts of memory.
This allocation size is derived from a
user-provided value
and could allocate arbitrary amounts of memory.
This allocation size is derived from a
user-provided value
and could allocate arbitrary amounts of memory.

Copilot Autofix

AI 3 days ago

General approach: Enforce reasonable upper bounds on user-controlled parameters that influence allocation (image width, height, and potentially the number of time steps) before calling raster_stream_to_png_bytes. If inputs exceed those bounds, reject the request with an appropriate error instead of proceeding. This limits maximum allocation size and avoids arithmetic overflows when computing buffer sizes.

Best concrete fix in this file:

  1. Introduce constants for maximum allowed WMS image width and height in wms.rs, e.g., MAX_WMS_WIDTH and MAX_WMS_HEIGHT. These should be large enough for practical use but finite; without broader project context, values like 4096 are a conservative, common choice.
  2. In wms_get_map’s inner compute_result function, before constructing query_rect and before calling raster_stream_to_png_bytes, validate request.width and request.height against these limits. If either exceeds the limit or is zero, return an error (reusing the project’s existing Error/ErrorResponse types where possible).
  3. Keep behavior unchanged for valid sizes; only oversize/invalid inputs will now cause an early error. The call to raster_stream_to_png_bytes remains as-is.

We only need to modify services/src/api/handlers/wms.rs:

  • Add two const definitions near the top-level (after imports or near other constants).
  • Add a small validation block inside compute_result before the existing let query_rect = ... line.

No changes are needed in services/src/api/ogc/util.rs.


Suggested changeset 1
services/src/api/handlers/wms.rs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/services/src/api/handlers/wms.rs b/services/src/api/handlers/wms.rs
--- a/services/src/api/handlers/wms.rs
+++ b/services/src/api/handlers/wms.rs
@@ -35,6 +35,10 @@
 use utoipa::openapi::{Ref, Required};
 use uuid::Uuid;
 
+/// Maximum allowed WMS image dimensions to prevent uncontrolled allocations.
+const MAX_WMS_WIDTH: u32 = 4096;
+const MAX_WMS_HEIGHT: u32 = 4096;
+
 pub(crate) fn init_wms_routes<C>(cfg: &mut web::ServiceConfig)
 where
     C: ApplicationContext,
@@ -436,6 +440,20 @@
 
         debug!("WMS re-scale-project: {:?}", query_tiling_pixel_grid);
 
+        // Guard against excessively large or zero-sized images to prevent uncontrolled allocations.
+        if request.width == 0
+            || request.height == 0
+            || request.width > MAX_WMS_WIDTH
+            || request.height > MAX_WMS_HEIGHT
+        {
+            return Err(Error::InvalidParams {
+                details: format!(
+                    "Requested image size {}x{} is invalid or exceeds maximum {}x{}",
+                    request.width, request.height, MAX_WMS_WIDTH, MAX_WMS_HEIGHT
+                ),
+            });
+        }
+
         let query_rect = RasterQueryRectangle::new(
             query_tiling_pixel_grid.grid_bounds(),
             query_time,
EOF
@@ -35,6 +35,10 @@
use utoipa::openapi::{Ref, Required};
use uuid::Uuid;

/// Maximum allowed WMS image dimensions to prevent uncontrolled allocations.
const MAX_WMS_WIDTH: u32 = 4096;
const MAX_WMS_HEIGHT: u32 = 4096;

pub(crate) fn init_wms_routes<C>(cfg: &mut web::ServiceConfig)
where
C: ApplicationContext,
@@ -436,6 +440,20 @@

debug!("WMS re-scale-project: {:?}", query_tiling_pixel_grid);

// Guard against excessively large or zero-sized images to prevent uncontrolled allocations.
if request.width == 0
|| request.height == 0
|| request.width > MAX_WMS_WIDTH
|| request.height > MAX_WMS_HEIGHT
{
return Err(Error::InvalidParams {
details: format!(
"Requested image size {}x{} is invalid or exceeds maximum {}x{}",
request.width, request.height, MAX_WMS_WIDTH, MAX_WMS_HEIGHT
),
});
}

let query_rect = RasterQueryRectangle::new(
query_tiling_pixel_grid.grid_bounds(),
query_time,
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants