Skip to content

Commit 158ada0

Browse files
authored
Add bound to VBlob returned from VImage.getBlob (#215)
1 parent 12e7579 commit 158ada0

4 files changed

Lines changed: 26 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ repositories {
2323
}
2424

2525
dependencies {
26-
implementation("app.photofox.vips-ffm:vips-ffm-core:1.9.6")
26+
implementation("app.photofox.vips-ffm:vips-ffm-core:1.9.7")
2727
}
2828
```
2929

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
plugins {
2-
kotlin("jvm") version "2.3.0" apply false
2+
kotlin("jvm") version "2.3.21" apply false
33
}

core/src/main/java/app/photofox/vipsffm/VImage.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10454,7 +10454,14 @@ public VBlob getBlob(String name) {
1045410454
if (!VipsValidation.isValidPointer(outPointer)) {
1045510455
throw new VipsError("failed to read value of type blob from field: " + name);
1045610456
}
10457-
var blobAddress = outPointer.get(VipsRaw.C_POINTER, 0);
10457+
if (!VipsValidation.isValidPointer(outLengthPointer)) {
10458+
throw new VipsError("failed to read length pointer of type blob from field: " + name);
10459+
}
10460+
var blobLength = outLengthPointer.get(VipsRaw.C_LONG, 0);
10461+
if (blobLength <= 0) {
10462+
throw new VipsError("failed to read length of type blob from field: " + name);
10463+
}
10464+
var blobAddress = outPointer.get(VipsRaw.C_POINTER, 0).reinterpret(blobLength);
1045810465
return new VBlob(arena, blobAddress);
1045910466
}
1046010467

generator/src/main/kotlin/vipsffm/GenerateVClasses.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,22 @@ object GenerateVClasses {
10721072

10731073
vblobType -> {
10741074
// void **
1075-
this.addStatement("var blobAddress = outPointer.get(\$T.C_POINTER, 0)", vipsRawType)
1075+
this.addCode(
1076+
CodeBlock.builder()
1077+
.beginControlFlow("if (!\$T.isValidPointer(outLengthPointer))", vipsValidatorType)
1078+
.addStatement("throw new VipsError(\"failed to read length pointer of type $typeName from field: \" + name)")
1079+
.endControlFlow()
1080+
.build()
1081+
)
1082+
this.addStatement("var blobLength = outLengthPointer.get(\$T.C_LONG, 0)", vipsRawType)
1083+
this.addCode(
1084+
CodeBlock.builder()
1085+
.beginControlFlow("if (blobLength <= 0)")
1086+
.addStatement("throw new VipsError(\"failed to read length of type $typeName from field: \" + name)")
1087+
.endControlFlow()
1088+
.build()
1089+
)
1090+
this.addStatement("var blobAddress = outPointer.get(\$T.C_POINTER, 0).reinterpret(blobLength)", vipsRawType)
10761091
this.addStatement("return new VBlob(arena, blobAddress)")
10771092
}
10781093

0 commit comments

Comments
 (0)