Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Calling partition() on an empty Table leads to a crash #11700

Closed
firestarman opened this issue Sep 14, 2022 · 1 comment · Fixed by #11709
Closed

[BUG] Calling partition() on an empty Table leads to a crash #11700

firestarman opened this issue Sep 14, 2022 · 1 comment · Fixed by #11709
Assignees
Labels
bug Something isn't working libcudf Affects libcudf (C++/CUDA) code.

Comments

@firestarman
Copy link
Contributor

firestarman commented Sep 14, 2022

Test to reproduce this bug.

  @Test
  void testPartitionEmptyTable() {
    try (Table t = new Table.TestBuilder()
        .timestampDayColumn()
        .build();
         ColumnVector parts = ColumnVector
             .fromInts();
         PartitionedTable pt = t.partition(parts, 3)) {
      assertArrayEquals(new int[]{0, 0, 0}, pt.getPartitions());
    }
  }

After building the libcudf, run the test as the follows

cd <path-to-cudf-root>/java
mvn test -Dtest=ai.rapids.cudf.TableTest#testPartitionEmptyTable

Crash stack

Stack: [0x00007f5e1e0c9000,0x00007f5e1e1c9000],  sp=0x00007f5e1e1c5868,  free space=1010k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libc.so.6+0x18b805]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  ai.rapids.cudf.Table.partition(JJI[I)[J+0
j  ai.rapids.cudf.Table.partition(Lai/rapids/cudf/ColumnView;I)Lai/rapids/cudf/PartitionedTable;+23
j  ai.rapids.cudf.TableTest.testPartitionEmptyTable()V+33
v  ~StubRoutines::call_stub
j  sun.reflect.NativeMethodAccessorImpl.invoke0(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+0
j  sun.reflect.NativeMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+100
j  sun.reflect.DelegatingMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+6
j  java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+56
j  org.junit.platform.commons.util.ReflectionUtils.invokeMethod(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+41
j  org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(Ljava/lang/reflect/Method;Ljava/lang/Object;Lorg/junit/jupiter/api/extension/ExtensionContext;Lorg/junit/jupiter/engine/extension/ExtensionRegistry;)Ljava/lang/Object;+32
j  org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(Lorg/junit/jupiter/api/extension/ExtensionContext;Lorg/junit/jupiter/engine/execution/JupiterEngineExecutionContext;)V+24
j  org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor$$Lambda$221.execute()V+12
j  org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(Lorg/junit/platform/engine/support/hierarchical/ThrowableCollector$Executable;)V+1
j  org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(Lorg/junit/jupiter/engine/execution/JupiterEngineExecutionContext;Lorg/junit/platform/engine/support/hierarchical/Node$DynamicTestExecutor;)V+21
j  org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(Lorg/junit/jupiter/engine/execution/JupiterEngineExecutionContext;Lorg/junit/platform/engine/support/hierarchical/Node$DynamicTestExecutor;)Lorg/junit/jupiter/engine/execution/JupiterEngineExecutionContext;+44

[UPDATES]
The crash happened at line #2644 . When row number is 0 (aka an empty table), the size of partition_offsets is 0, then partition_offsets.end() - 1 points to an invalid address. But according to the partition's doc, the size of partition_offsets should be num_partitions + 1.

@firestarman firestarman added bug Something isn't working Needs Triage Need team to review and classify labels Sep 14, 2022
@firestarman firestarman changed the title [BUG] [Java] Calling partition() on an empty Table leads to a crash [BUG] [JNI] Calling partition() on an empty Table leads to a crash Sep 14, 2022
@firestarman
Copy link
Contributor Author

The crash happened at line #2644 . When row number is 0 (aka an empty table), the size of partition_offsets is 0, then partition_offsets.end() - 1 points to an invalid address.

@davidwendt davidwendt added the Java Affects Java cuDF API. label Sep 14, 2022
@firestarman firestarman added libcudf Affects libcudf (C++/CUDA) code. and removed Java Affects Java cuDF API. labels Sep 14, 2022
@firestarman firestarman changed the title [BUG] [JNI] Calling partition() on an empty Table leads to a crash [BUG] Calling partition() on an empty Table leads to a crash Sep 14, 2022
rapids-bot bot pushed a commit that referenced this issue Sep 27, 2022
…ut table (#11709)

By definition, the `cudf::partition*` API will return a vector of offsets with size is at least the number of partitions. As such, an output empty table should associate with an output offset array like `[0, 0, ..., 0]` (all zeros). However, currently the output offsets in such situations is an empty array.

This PR corrects the implementation for such corner cases.

Closes #11700.

Authors:
  - Nghia Truong (https://github.com/ttnghia)

Approvers:
  - GALI PREM SAGAR (https://github.com/galipremsagar)
  - Vukasin Milovanovic (https://github.com/vuule)
  - Mike Wilson (https://github.com/hyperbolic2346)

URL: #11709
@bdice bdice removed the Needs Triage Need team to review and classify label Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working libcudf Affects libcudf (C++/CUDA) code.
Projects
None yet
4 participants