Skip to content

Commit acc0699

Browse files
committed
Add src upload offset check
1 parent 03d470e commit acc0699

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/main/java/net/vulkanmod/vulkan/texture/VulkanImage.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.lwjgl.vulkan.VkImageMemoryBarrier;
1515
import org.lwjgl.vulkan.VkImageViewCreateInfo;
1616

17+
import java.nio.BufferOverflowException;
1718
import java.nio.ByteBuffer;
1819
import java.nio.LongBuffer;
1920
import java.util.Arrays;
@@ -215,7 +216,13 @@ public void uploadSubTextureAsync(int mipLevel, int width, int height, int xOffs
215216
try (MemoryStack stack = stackPush()) {
216217
transferDstLayout(stack, commandBuffer);
217218

218-
final int srcOffset = (int) (stagingBuffer.getOffset() + (unpackRowLength * unpackSkipRows + unpackSkipPixels) * this.formatSize);
219+
int uploadOffset = (unpackRowLength * unpackSkipRows + unpackSkipPixels) * this.formatSize;
220+
221+
if (uploadOffset > uploadSize) {
222+
throw new BufferOverflowException();
223+
}
224+
225+
final int srcOffset = (int) (stagingBuffer.getOffset() + uploadOffset);
219226

220227
ImageUtil.copyBufferToImageCmd(stack, commandBuffer, bufferId, this.id, mipLevel, width, height, xOffset, yOffset,
221228
srcOffset, unpackRowLength, height);

0 commit comments

Comments
 (0)