Github user vanzin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5400#discussion_r31541648
  
    --- Diff: 
core/src/main/scala/org/apache/spark/util/io/ByteArrayChunkOutputStream.scala 
---
    @@ -91,4 +95,45 @@ class ByteArrayChunkOutputStream(chunkSize: Int) extends 
OutputStream {
           ret
         }
       }
    +
    +  /**
    +   * Get a copy of the data between the two endpoints, start <= idx < 
until.  Always returns
    +   * an array of size (until - start).  Throws an IllegalArgumentException 
if
    +   * 0 <= start <= until <= size
    +   */
    +  def slice(start: Long, until: Long): Array[Byte] = {
    +    require((until - start) < Integer.MAX_VALUE, "max slice length = 
Integer.MAX_VALUE")
    +    require(start >= 0 && start <= until, s"start ($start) must be >= 0 
and <= until ($until)")
    +    require(until >= start && until <= size,
    +      s"until ($until) must be >= start ($start) and <= size ($size)")
    +    var chunkStart = 0L
    +    var chunkIdx = 0
    +    val length = (until - start).toInt
    +    var foundStart = false
    +    val result = new Array[Byte](length)
    +    while (!foundStart) {
    +      val nextSize = chunkStart + chunks(chunkIdx).size
    --- End diff --
    
    This feels wrong. You're comparing `start` to the added size of the last 
two chunks, not to the cumulative size of all previous chunks.
    
    I think L119 should be a `+=` instead of plain `=`, and maybe you need a 
better named variable than `chunkStart`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to