Skip to content

Commit

Permalink
#1579 Resolves issue with array index out of bounds error generated i…
Browse files Browse the repository at this point in the history
…n P25 Phase 1 decoders where the Dibit circular buffer attempts to write a

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.
  • Loading branch information
Dennis Sheirer committed Jun 24, 2023
1 parent e04b59b commit f51db06
Showing 1 changed file with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>
* * *****************************************************************************
* 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 <http://www.gnu.org/licenses/>
* ****************************************************************************
*/
package io.github.dsheirer.module.decode.p25.phase1;

Expand Down Expand Up @@ -493,6 +490,13 @@ public int[] getBufferAsArray()
*/
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)
Expand Down

0 comments on commit f51db06

Please sign in to comment.