From f144c2ae6c6e8647213939a409259ae738413bb8 Mon Sep 17 00:00:00 2001 From: sage <149851+lopcode@users.noreply.github.com> Date: Thu, 7 May 2026 18:15:14 +0200 Subject: [PATCH] Add bound to VBlob returned from VImage.getBlob --- README.md | 2 +- build.gradle.kts | 2 +- .../main/java/app/photofox/vipsffm/VImage.java | 9 ++++++++- .../src/main/kotlin/vipsffm/GenerateVClasses.kt | 17 ++++++++++++++++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6896d86..d31a43a 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ repositories { } dependencies { - implementation("app.photofox.vips-ffm:vips-ffm-core:1.9.6") + implementation("app.photofox.vips-ffm:vips-ffm-core:1.9.7") } ``` diff --git a/build.gradle.kts b/build.gradle.kts index 6bb3be3..ddb219e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,3 @@ plugins { - kotlin("jvm") version "2.3.0" apply false + kotlin("jvm") version "2.3.21" apply false } \ No newline at end of file diff --git a/core/src/main/java/app/photofox/vipsffm/VImage.java b/core/src/main/java/app/photofox/vipsffm/VImage.java index 9776569..b5fc436 100644 --- a/core/src/main/java/app/photofox/vipsffm/VImage.java +++ b/core/src/main/java/app/photofox/vipsffm/VImage.java @@ -10454,7 +10454,14 @@ public VBlob getBlob(String name) { if (!VipsValidation.isValidPointer(outPointer)) { throw new VipsError("failed to read value of type blob from field: " + name); } - var blobAddress = outPointer.get(VipsRaw.C_POINTER, 0); + if (!VipsValidation.isValidPointer(outLengthPointer)) { + throw new VipsError("failed to read length pointer of type blob from field: " + name); + } + var blobLength = outLengthPointer.get(VipsRaw.C_LONG, 0); + if (blobLength <= 0) { + throw new VipsError("failed to read length of type blob from field: " + name); + } + var blobAddress = outPointer.get(VipsRaw.C_POINTER, 0).reinterpret(blobLength); return new VBlob(arena, blobAddress); } diff --git a/generator/src/main/kotlin/vipsffm/GenerateVClasses.kt b/generator/src/main/kotlin/vipsffm/GenerateVClasses.kt index f2d1d12..5beb7c4 100644 --- a/generator/src/main/kotlin/vipsffm/GenerateVClasses.kt +++ b/generator/src/main/kotlin/vipsffm/GenerateVClasses.kt @@ -1072,7 +1072,22 @@ object GenerateVClasses { vblobType -> { // void ** - this.addStatement("var blobAddress = outPointer.get(\$T.C_POINTER, 0)", vipsRawType) + this.addCode( + CodeBlock.builder() + .beginControlFlow("if (!\$T.isValidPointer(outLengthPointer))", vipsValidatorType) + .addStatement("throw new VipsError(\"failed to read length pointer of type $typeName from field: \" + name)") + .endControlFlow() + .build() + ) + this.addStatement("var blobLength = outLengthPointer.get(\$T.C_LONG, 0)", vipsRawType) + this.addCode( + CodeBlock.builder() + .beginControlFlow("if (blobLength <= 0)") + .addStatement("throw new VipsError(\"failed to read length of type $typeName from field: \" + name)") + .endControlFlow() + .build() + ) + this.addStatement("var blobAddress = outPointer.get(\$T.C_POINTER, 0).reinterpret(blobLength)", vipsRawType) this.addStatement("return new VBlob(arena, blobAddress)") }