Browse Source

Fix: successfully read 0 bytes when client
resumes from end of response

Rod Hynes 9 years ago
parent
commit
cbd4affa16
2 changed files with 9 additions and 0 deletions
  1. 7 0
      psiphon/server/meekBuffer.go
  2. 2 0
      psiphon/server/meek_test.go

+ 7 - 0
psiphon/server/meekBuffer.go

@@ -102,6 +102,8 @@ func (response *CachedResponse) HasPosition(position int) bool {
 // the specified position, to writer. Any data before the
 // position is skipped. CopyFromPosition will return an error
 // if the specified position is not available.
+// CopyFromPosition will copy no data and return no error if
+// the position is at the end of its available data.
 // CopyFromPosition can be called repeatedly to read the
 // same data -- it does not advance or modify the CachedResponse.
 func (response *CachedResponse) CopyFromPosition(
@@ -111,6 +113,11 @@ func (response *CachedResponse) CopyFromPosition(
 		return errors.New("position unavailable")
 	}
 
+	// Special case: position is end of available data
+	if position == response.readPosition+response.readAvailable {
+		return nil
+	}
+
 	// Begin at the start of the response data, which may
 	// be midway through the buffer(s).
 

+ 2 - 0
psiphon/server/meek_test.go

@@ -62,6 +62,8 @@ func TestCachedResponse(t *testing.T) {
 
 		{1, 31, 15, 3, 5, 1, 1, 1, true},
 
+		{1, 16, 16, 0, 0, 1, 1, 16, true},
+
 		{1, 10 * MB, 64 * KB, 64 * KB, 158, 1, 32 * KB, 0, false},
 
 		{1, 10 * MB, 64 * KB, 64 * KB, 159, 1, 32 * KB, 0, true},