github-code-scanning[bot] commented on code in PR #14142:
URL: https://github.com/apache/druid/pull/14142#discussion_r1174164202


##########
processing/src/main/java/org/apache/druid/segment/serde/CombineFirstTwoValuesIndexedInts.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.segment.serde;
+
+import org.apache.druid.common.config.NullHandling;
+import org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector;
+import org.apache.druid.segment.data.Indexed;
+import org.apache.druid.segment.data.IndexedInts;
+
+/**
+ * A {@link IndexedInts} that delegates to an underyling instance, but 
combines the values 0 and 1 into 0.
+ *
+ * This class combines *values*, not *indexes*. So [0, 1, 2] becomes [0, 0, 
2]. (The 1 was replaced with a 0.)
+ *
+ * Provided to enable compatibility for segments written under {@link 
NullHandling#sqlCompatible()} mode but
+ * read under {@link NullHandling#replaceWithDefault()} ()} mode.
+ *
+ * @see NullHandling#mustCombineNullAndEmpty(Indexed)
+ */
+public class CombineFirstTwoValuesIndexedInts implements IndexedInts
+{
+  private static final int NULL_ID = 0;
+
+  protected final IndexedInts delegate;
+
+  public CombineFirstTwoValuesIndexedInts(IndexedInts delegate)
+  {
+    this.delegate = delegate;
+  }
+
+  @Override
+  public int size()
+  {
+    return delegate.size();
+  }
+
+  @Override
+  public int get(int index)
+  {
+    final int i = delegate.get(index);
+    if (i == NULL_ID) {
+      return i;
+    } else {
+      return i - 1;

Review Comment:
   ## User-controlled data in arithmetic expression
   
   This arithmetic expression depends on a [user-provided value](1), 
potentially causing an underflow.
   This arithmetic expression depends on a [user-provided value](2), 
potentially causing an underflow.
   This arithmetic expression depends on a [user-provided value](3), 
potentially causing an underflow.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/4865)



##########
processing/src/main/java/org/apache/druid/segment/serde/CombineFirstTwoEntriesIndexed.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.segment.serde;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.druid.collections.bitmap.BitmapFactory;
+import org.apache.druid.collections.bitmap.ImmutableBitmap;
+import org.apache.druid.common.config.NullHandling;
+import org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector;
+import org.apache.druid.segment.data.Indexed;
+
+import javax.annotation.Nullable;
+import java.util.Iterator;
+import java.util.Objects;
+
+/**
+ * An {@link Indexed} that delegates to an underyling instance, but combines 
the first two entries.
+ *
+ * Unlike {@link CombineFirstTwoValuesIndexedInts}, this class combines the 
first two *entries*.
+ * So [0, 1, 2] becomes [(something), 2]. The first two entries, 0 and 1, were 
replaced with (something). That something
+ * is given by {@link #newFirstValue()}.
+ *
+ * Provided to enable compatibility for segments written under {@link 
NullHandling#sqlCompatible()} mode but
+ * read under {@link NullHandling#replaceWithDefault()} mode.
+ *
+ * @see NullHandling#mustCombineNullAndEmpty(Indexed)
+ */
+public abstract class CombineFirstTwoEntriesIndexed<T> implements Indexed<T>
+{
+  private static final int FIRST_ID = 0;
+
+  protected final Indexed<T> delegate;
+
+  protected CombineFirstTwoEntriesIndexed(Indexed<T> delegate)
+  {
+    this.delegate = delegate;
+  }
+
+  /**
+   * Combine the first two values into a literal null.
+   */
+  public static <T> CombineFirstTwoEntriesIndexed<T> returnNull(final 
Indexed<T> delegate)
+  {
+    return new CombineFirstTwoEntriesIndexed<T>(delegate)
+    {
+      @Nullable
+      @Override
+      protected T newFirstValue()
+      {
+        return null;
+      }
+    };
+  }
+
+  /**
+   * Union the first two bitmaps.
+   */
+  public static CombineFirstTwoEntriesIndexed<ImmutableBitmap> unionBitmaps(
+      final BitmapFactory bitmapFactory,
+      final Indexed<ImmutableBitmap> delegate
+  )
+  {
+    return new CombineFirstTwoEntriesIndexed<ImmutableBitmap>(delegate)
+    {
+      @Nullable
+      @Override
+      protected ImmutableBitmap newFirstValue()
+      {
+        return bitmapFactory.union(ImmutableList.of(delegate.get(FIRST_ID), 
delegate.get(FIRST_ID + 1)));
+      }
+    };
+  }
+
+  @Nullable
+  protected abstract T newFirstValue();
+
+  @Override
+  public int size()
+  {
+    return delegate.size() - 1;
+  }
+
+  @Nullable
+  @Override
+  public T get(int index)
+  {
+    if (index == FIRST_ID) {
+      return newFirstValue();
+    } else {
+      return delegate.get(index + 1);

Review Comment:
   ## User-controlled data in arithmetic expression
   
   This arithmetic expression depends on a [user-provided value](1), 
potentially causing an overflow.
   This arithmetic expression depends on a [user-provided value](2), 
potentially causing an overflow.
   This arithmetic expression depends on a [user-provided value](3), 
potentially causing an overflow.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/4864)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to