diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index 635337496..23fcf8c49 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -676,6 +676,11 @@ cogl_texture_set_region_from_bitmap (CoglTexture *texture,
{
gboolean ret;
+ _COGL_RETURN_VAL_IF_FAIL ((_cogl_bitmap_get_width (bmp) - src_x)
+ >= dst_width, FALSE);
+ _COGL_RETURN_VAL_IF_FAIL ((_cogl_bitmap_get_height (bmp) - src_y)
+ >= dst_height, FALSE);
+
/* Shortcut out early if the image is empty */
if (dst_width == 0 || dst_height == 0)
return TRUE;
@@ -713,6 +718,9 @@ cogl_texture_set_region (CoglTexture *texture,
CoglBitmap *source_bmp;
gboolean ret;
+ _COGL_RETURN_VAL_IF_FAIL ((width - src_x) >= dst_width, FALSE);
+ _COGL_RETURN_VAL_IF_FAIL ((height - src_y) >= dst_height, FALSE);
+
/* Check for valid format */
if (format == COGL_PIXEL_FORMAT_ANY)
return FALSE;
diff --git a/cogl/cogl-texture.h b/cogl/cogl-texture.h
index ed947de9a..6fedfb25a 100644
--- a/cogl/cogl-texture.h
+++ b/cogl/cogl-texture.h
@@ -366,8 +366,10 @@ cogl_texture_get_data (CoglTexture *texture,
* @src_y: upper left coordinate to use from source data.
* @dst_x: upper left destination horizontal coordinate.
* @dst_y: upper left destination vertical coordinate.
- * @dst_width: width of destination region to write.
- * @dst_height: height of destination region to write.
+ * @dst_width: width of destination region to write. (Must be less
+ * than or equal to @width)
+ * @dst_height: height of destination region to write. (Must be less
+ * than or equal to @height)
* @width: width of source data buffer.
* @height: height of source data buffer.
* @format: the #CoglPixelFormat used in the source buffer.
@@ -375,9 +377,11 @@ cogl_texture_get_data (CoglTexture *texture,
* specified)
* @data: the actual pixel data.
*
- * Sets the pixels in a rectangular subregion of @handle from an in-memory
+ * Sets the pixels in a rectangular subregion of @texture from an in-memory
* buffer containing pixel data.
*
+ * The region set can't be larger than the source @data
+ *
* Return value: %TRUE if the subregion upload was successful, and
* %FALSE otherwise
*/
@@ -406,13 +410,18 @@ cogl_texture_set_region (CoglTexture *texture,
* @src_y: upper left coordinate to use from the source bitmap
* @dst_x: upper left destination horizontal coordinate.
* @dst_y: upper left destination vertical coordinate.
- * @dst_width: width of destination region to write.
- * @dst_height: height of destination region to write.
+ * @dst_width: width of destination region to write. (Must be less
+ * than or equal to the bitmap width)
+ * @dst_height: height of destination region to write. (Must be less
+ * than or equal to the bitmap height)
* @bitmap: The source bitmap to read from
*
* Copies a specified source region from @bitmap to the position
* (@src_x, @src_y) of the given destination texture @handle.
*
+ * The region updated can't be larger than the source
+ * bitmap
+ *
* Return value: %TRUE if the subregion upload was successful, and
* %FALSE otherwise
*