[rygel] core: Fix out of bounds seek response



commit c5889064ba6fc3442db1392bf5cd62f4cf5f9e14
Author: Luis de Bethencourt <luis debethencourt collabora co uk>
Date:   Fri May 6 19:12:17 2011 +0200

    core: Fix out of bounds seek response
    
    Fixes CTT test cases: 7.4.38.6 & 7.4.40.8

 src/rygel/rygel-http-get.vala      |   12 ++++++++----
 src/rygel/rygel-http-response.vala |    5 ++++-
 src/rygel/rygel-http-seek.vala     |   11 ++++++++++-
 3 files changed, 22 insertions(+), 6 deletions(-)
---
diff --git a/src/rygel/rygel-http-get.vala b/src/rygel/rygel-http-get.vala
index a8fc006..24e6251 100644
--- a/src/rygel/rygel-http-get.vala
+++ b/src/rygel/rygel-http-get.vala
@@ -138,10 +138,14 @@ internal class Rygel.HTTPGet : HTTPRequest {
             throw new HTTPRequestError.UNACCEPTABLE ("Invalid seek request");
         }
 
-        if (need_time_seek) {
-            this.seek = new HTTPTimeSeek (this);
-        } else if (need_byte_seek) {
-            this.seek = new HTTPByteSeek (this);
+        try {
+            if (need_time_seek) {
+                this.seek = new HTTPTimeSeek (this);
+            } else if (need_byte_seek) {
+                this.seek = new HTTPByteSeek (this);
+            }
+        } catch (Error error) {
+            this.end (Soup.KnownStatusCode.REQUESTED_RANGE_NOT_SATISFIABLE);
         }
 
         // Add headers
diff --git a/src/rygel/rygel-http-response.vala b/src/rygel/rygel-http-response.vala
index 4cc137e..423df4d 100644
--- a/src/rygel/rygel-http-response.vala
+++ b/src/rygel/rygel-http-response.vala
@@ -68,7 +68,10 @@ internal class Rygel.HTTPResponse : GLib.Object, Rygel.StateMachine {
         this.cancellable = request_handler.cancellable;
         this.seek = request.seek;
 
-        if (this.seek != null && this.seek.length < this.seek.total_length) {
+        var range = this.msg.request_headers.get_one("Range");
+        if ((this.seek != null &&
+            this.seek.length < this.seek.total_length) ||
+            range != null) {
             this.msg.set_status (Soup.KnownStatusCode.PARTIAL_CONTENT);
         } else {
             this.msg.set_status (Soup.KnownStatusCode.OK);
diff --git a/src/rygel/rygel-http-seek.vala b/src/rygel/rygel-http-seek.vala
index 83bf355..1518e63 100644
--- a/src/rygel/rygel-http-seek.vala
+++ b/src/rygel/rygel-http-seek.vala
@@ -40,13 +40,22 @@ internal abstract class Rygel.HTTPSeek : GLib.Object {
                      int64        start,
                      int64        stop,
                      int64        step,
-                     int64        total_length) {
+                     int64        total_length) throws HTTPSeekError {
         this.msg = msg;
         this.start = start;
         this.stop = stop;
         this.length = length;
         this.total_length = total_length;
 
+        if (start < 0 || start > total_length) {
+            throw new HTTPSeekError.OUT_OF_RANGE (_("Out Of Range Start '%ld'"),
+                                                  start);
+        }
+        if (stop < 0 || stop > total_length) {
+            throw new HTTPSeekError.OUT_OF_RANGE (_("Out Of Range Stop '%ld'"),
+                                                  stop);
+        }
+
         if (length > 0) {
             this.stop = stop.clamp (start + 1, length - 1);
         }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]