[squeak-dev] The Inbox: Network-tonyg.186.mcz

Tony Garnock-Jones tonyg at ccs.neu.edu
Thu Feb 23 17:46:45 UTC 2017


What do people think of this proposed fix?

I think it, at worst, does no harm, and makes the tests I added in
NetworkTests-tonyg.44 pass.

Tony

PS. Using the 6.0alpha has been really, really pleasant. Kudos to all
who have made it such a great experience.



On 02/19/2017 05:01 PM, commits at source.squeak.org wrote:
> A new version of Network was added to project The Inbox:
> http://source.squeak.org/inbox/Network-tonyg.186.mcz
> 
> ==================== Summary ====================
> 
> Name: Network-tonyg.186
> Author: tonyg
> Time: 19 February 2017, 12:00:54.097194 pm
> UUID: e9ef40b8-5a51-460a-b2cf-54d43fca0b9c
> Ancestors: Network-tfel.185
> 
> Clamp start position in search in SocketStream>>upToAll: to avoid out-of-bounds access when searching in binary mode. Proposed fix for problems highlighted by tests included in NetworkTests-tonyg.44.
> 
> =============== Diff against Network-tfel.185 ===============
> 
> Item was changed:
>   ----- Method: SocketStream>>upToAll:limit: (in category 'stream in') -----
>   upToAll: aStringOrByteArray limit: nBytes
>   	"Answer a subcollection from the current access position to the occurrence (if any, but not inclusive) of aStringOrByteArray. If aCollection is not in the stream, or not found within nBytes answer the available contents of the stream"
>   
>   	| index sz result searchedSoFar target |
>   	"Deal with ascii vs. binary"
>   	self isBinary
>   		ifTrue:[target := aStringOrByteArray asByteArray]
>   		ifFalse:[target := aStringOrByteArray asString].
>   
>   	sz := target size.
>   	"Look in the current inBuffer first"
>   	index := inBuffer indexOfSubCollection: target
> + 						startingAt: ((lastRead - sz + 2) max: 1).
> - 						startingAt: lastRead - sz + 2.
>   	(index > 0 and: [(index + sz) <= inNextToWrite]) ifTrue: ["found it"
>   		result := self nextInBuffer: index - lastRead - 1.
>   		self skip: sz.
>   		^ result
>   	].
>   
>   	[searchedSoFar :=  self inBufferSize.
>   	"Receive more data"
>   	self receiveData.
>   	recentlyRead > 0] whileTrue:[
>   
>   		"Data begins at lastRead + 1, we add searchedSoFar as offset and 
>   		backs up sz - 1 so that we can catch any borderline hits."
>   
>   		index := inBuffer indexOfSubCollection: target
>   						startingAt: (lastRead + searchedSoFar - sz + 2 max: 1).
>   		(index > 0 and: [(index + sz) <= inNextToWrite]) ifTrue: ["found it"
>   			result := self nextInBuffer: index - lastRead - 1.
>   			self skip: sz.
>   			^ result
>   		].
>   		"Check if we've exceeded the max. amount"
>   		(nBytes notNil and:[inNextToWrite - lastRead > nBytes]) 
>   			ifTrue:[^self nextAllInBuffer].
>   	].
>   
>   	"not found and (non-signaling) connection was closed"
>   	^self nextAllInBuffer!
> 
> 


More information about the Squeak-dev mailing list