Commit d29d922e authored by Hiro's avatar Hiro 🏄
Browse files

Merge branch 'bug_40021_v2' into 'master'

Avoid out-of-memory situation due to faulty descriptor

Closes #40021

See merge request tpo/network-health/metrics/library!16
parents 89f7a15f a1a32157
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -83,7 +83,8 @@ public abstract class DescriptorImpl implements Descriptor {
   *
   * @param offset The index of the first byte to include.
   * @param length The number of bytes to include.
   * @return Copy of the given raw descriptor bytes.
   * @return Copy of the given raw descriptor bytes or null in case of running
   *         out of memory.
   */
  protected byte[] getRawDescriptorBytes(int offset, int length) {
    if (offset < this.offset || offset + length > this.offset + this.length
@@ -93,7 +94,11 @@ public abstract class DescriptorImpl implements Descriptor {
          + this.length);
    }
    byte[] result = new byte[length];
    try {
      System.arraycopy(this.rawDescriptorBytes, offset, result, 0, length);
    } catch (OutOfMemoryError err) {
      return null;
    }
    return result;
  }