From b2ab6f58e9d6303e4e9317c118902bb79dbbcd29 Mon Sep 17 00:00:00 2001 From: Denny Sheirer Date: Sat, 24 Jun 2023 06:09:57 -0400 Subject: [PATCH] #1579 Resolves issue with array index out of bounds error generated in P25 Phase 1 decoders where the Dibit circular buffer attempts to write a (#1580) dibit past the length of the array. Issue likely occurs when a partial/incomplete put operation adds a dibit and increments the buffer pointer but the thread is interrupted prior to wrapping the buffer pointer. When the next runnable iteration executes, the pointer is pointing past the end of the buffer. Updates the code to check the pointer both before and after the put operation. Co-authored-by: Dennis Sheirer --- .../p25/phase1/P25P1DataUnitDetector.java | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/main/java/io/github/dsheirer/module/decode/p25/phase1/P25P1DataUnitDetector.java b/src/main/java/io/github/dsheirer/module/decode/p25/phase1/P25P1DataUnitDetector.java index 274e0cd5..a2ba2ec8 100644 --- a/src/main/java/io/github/dsheirer/module/decode/p25/phase1/P25P1DataUnitDetector.java +++ b/src/main/java/io/github/dsheirer/module/decode/p25/phase1/P25P1DataUnitDetector.java @@ -1,23 +1,20 @@ /* + * ***************************************************************************** + * Copyright (C) 2014-2023 Dennis Sheirer * - * * ****************************************************************************** - * * Copyright (C) 2014-2020 Dennis Sheirer - * * - * * This program is free software: you can redistribute it and/or modify - * * it under the terms of the GNU General Public License as published by - * * the Free Software Foundation, either version 3 of the License, or - * * (at your option) any later version. - * * - * * This program is distributed in the hope that it will be useful, - * * but WITHOUT ANY WARRANTY; without even the implied warranty of - * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * * GNU General Public License for more details. - * * - * * You should have received a copy of the GNU General Public License - * * along with this program. If not, see - * * ***************************************************************************** + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + * **************************************************************************** */ package io.github.dsheirer.module.decode.p25.phase1; @@ -493,6 +490,13 @@ public class P25P1DataUnitDetector implements Listener, ISyncDetectListen */ public void put(Dibit dibit) { + //Note: this check is necessary where the previous runnable was interrupted and left the buffer + //pointer pointing past the end of the array length. + if(mPointer >= mBuffer.length) + { + mPointer = 0; + } + mBuffer[mPointer++] = dibit; if(mPointer >= mBuffer.length)