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

    https://github.com/apache/spark/pull/18730#discussion_r134786732
  
    --- Diff: 
core/src/main/scala/org/apache/spark/util/io/ChunkedByteBuffer.scala ---
    @@ -63,6 +65,19 @@ private[spark] class ChunkedByteBuffer(var chunks: 
Array[ByteBuffer]) {
       }
     
       /**
    +   * Write this buffer to a channel with slice.
    +   */
    +  def writeWithSlice(channel: WritableByteChannel): Unit = {
    +    for (bytes <- getChunks()) {
    +      val capacity = bytes.limit()
    +      while (bytes.position() < capacity) {
    +        bytes.limit(Math.min(capacity, bytes.position + 
NIO_BUFFER_LIMIT.toInt))
    --- End diff --
    
    Should we replace `Math.min(...)` with `Math.min(capacity, bytes.position + 
NIO_BUFFER_LIMIT.toLong)`? I am afraid int underflow. For example, if `capacity 
= 0x7FFFFFF0` and `bytes.position = 0x7FFFFF00`, the result of `bytes.position 
+ NIO_BUFFER_LIMIT.toLong` is negative (i.e. greater than 0x80000000).
    To avoid this underflow, it would be good to compare them by using `long`.


---
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