Skip to content

Commit

Permalink
Merge pull request #81 from clhodapp/fix-unsafe-data-sharing
Browse files Browse the repository at this point in the history
Fix unsafe ChannelBuffer sharing for Nones in ValueEncoder
  • Loading branch information
jeremyrsmith authored Aug 14, 2018
2 parents 3d4ab10 + e582db3 commit fe28d32
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object ValueEncoder extends LowPriorityEncoder {

def encodeText[T](t: T, encoder: ValueEncoder[T], charset: Charset = StandardCharsets.UTF_8) =
Option(t).flatMap(encoder.encodeText) match {
case None => nullParam
case None => nullParam.duplicate()
case Some(str) =>
val bytes = str.getBytes(charset)
val buf = ChannelBuffers.buffer(bytes.length + 4)
Expand All @@ -74,7 +74,7 @@ object ValueEncoder extends LowPriorityEncoder {

def encodeBinary[T](t: T, encoder: ValueEncoder[T], charset: Charset = StandardCharsets.UTF_8) =
Option(t).flatMap(encoder.encodeBinary(_, charset)) match {
case None => nullParam
case None => nullParam.duplicate()
case Some(inBuf) =>
inBuf.resetReaderIndex()
val outBuf = ChannelBuffers.buffer(inBuf.readableBytes() + 4)
Expand Down

0 comments on commit fe28d32

Please sign in to comment.