Skip to content

Commit

Permalink
Fix painless casting bug causing opensearch to crash (opensearch-proj…
Browse files Browse the repository at this point in the history
…ect#8315)

* Created a failing test to reproduce painless bug

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed unused import

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Throw exception when trying to cast def to void

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Removed update context change

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

* Created a different test

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>

---------

Signed-off-by: Shivansh Arora <shivansh.arora@protonmail.com>
Signed-off-by: Shivansh Arora <hishiv@amazon.com>
  • Loading branch information
shiv0408 committed Apr 25, 2024
1 parent 75e1478 commit 4a65713
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Replaces ZipInputStream with ZipFile to fix Zip Slip vulnerability ([#7230](https://github.com/opensearch-project/OpenSearch/pull/7230))
- Add missing validation/parsing of SearchBackpressureMode of SearchBackpressureSettings ([#7541](https://github.com/opensearch-project/OpenSearch/pull/7541))
- Adds log4j configuration for telemetry LogSpanExporter ([#8393](https://github.com/opensearch-project/OpenSearch/pull/8393))
- Fix painless casting bug, which crashes the OpenSearch process ([#8315](https://github.com/opensearch-project/OpenSearch/pull/8315))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public static PainlessCast getLegalCast(Location location, Class<?> actual, Clas
}
}

if (actual == def.class
if ((actual == def.class && expected != void.class)
|| (actual != void.class && expected == def.class)
|| expected.isAssignableFrom(actual)
|| (actual.isAssignableFrom(expected) && explicit)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,14 @@ public void testVoidReturn() {
assertEquals(iae.getMessage(), "not a statement: result not used from addition operation [+]");
}

public void testDefToVoidReturnThrowsException() {
ClassCastException exception = expectScriptThrows(
ClassCastException.class,
() -> getEngine().compile("def_return_in_void", "def x=1;return x;", VoidReturnTestScript.CONTEXT, Collections.emptyMap())
);
assertEquals(exception.getMessage(), "Cannot cast from [def] to [void].");
}

public abstract static class FactoryTestConverterScript {
private final Map<String, Object> params;

Expand Down

0 comments on commit 4a65713

Please sign in to comment.