jrAudioPro2 - HTTP 500 while rendering its chart

serveion
@serveion
yesterday
225 posts
Hello Guys

I was doing maintenance on my website, and I found this error on the page; I couldn't find a place to submit this, so I posted here: :-)

jrCharts 1.2.1 can return HTTP 500 when a chart counter is nonnumeric

Environment
  • Site:
  • Jamroom Core: 7.0.3
  • jrCharts: 1.2.1
  • Production PHP and Apache: versions unverified
  • Local reproduction: PHP 8.5.12 CLI on Windows
Symptom

The domain homepage returned HTTP 500 while rendering its chart. The active skin was xxxxxxx. The same code path can affect jrAudioPro2 when it requests a chart.

The PHP log reported this error in modules/jrCharts/include.php at line 271, inside jrCharts_db_search_params_listener().

TypeError: Unsupported operand types: string - int

Cause and reproduction

The listener calculates the chart delta with (int) ($count - $_ce[$iid]). PHP evaluates the subtraction before casting the result. The original isset() check verifies that a historical value exists, so a nonnumeric counter can still reach the subtraction.

The reproduction fixture triggers the error with a nonnumeric current counter and a numeric historical counter. The exact stored value that triggered the production error is unknown.

Code comparison

The patch validates both counters before subtraction and skips invalid rows. Numeric strings and tracks with no historical entry retain their existing behavior.

 foreach ($_cb as $iid => $count) {
-    if (isset($_ce[$iid])) {
+    $has_history = array_key_exists($iid, $_ce);
+    if (!is_numeric($count) || ($has_history && !is_numeric($_ce[$iid]))) {
+        // An invalid counter cannot produce a meaningful chart position.
+        unset($_ce[$iid]);
+        continue;
+    }
+    if ($has_history) {
         // We have a history entry - get diff
         $GLOBALS["{$_args['module']}_jrcharts_cnt"][$iid] = (int) ($count - $_ce[$iid]);
         $GLOBALS["{$_args['module']}_jrcharts_old"][$iid] = $num++;

Historical JSON that decodes to a value other than an array is treated as missing history.

 $_ce = json_decode($_ce['chart_counts'], true);
+if (!is_array($_ce)) {
+    $_ce = array();
+}

When no valid counters remain, the patch preserves the existing search filters and adds a condition that returns an empty chart.

 arsort($GLOBALS["{$_args['module']}_jrcharts_cnt"], SORT_NUMERIC);

+// An empty ID list must not turn a chart into an unfiltered item list.
+if (!$GLOBALS["{$_args['module']}_jrcharts_cnt"]) {
+    $_data['search'][] = '_item_id < 0';
+    return $_data;
+}

Verification

The original file reproduced the TypeError. The patched file passed PHP lint and the regression fixture. The fixture covers invalid current and historical counters, numeric strings, missing history, result limits, preserved filters, and an empty result when every counter is invalid.

After deployment, the homepage, audio listing, chart page, and chart refresh returned HTTP 200.
updated by @serveion: 11/17/26 09:00:31AM
brian
@brian
13 hours ago
10,171 posts
Thank you for the detailed bug report - will get this fixed up.

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
brian
@brian
13 hours ago
10,171 posts
If you get a chance, please check out the new JR 7.1.0 beta release - I believe this is already fixed:

https://www.jamroom.net/the-jamroom-network/networkmarket/992/advanced-charts

Let me know if you can update a beta site to the new beta and still see an issue.

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
serveion
@serveion
13 hours ago
225 posts
Hello Brian

No problem, I'm working on refreshing the page and creating a new theme using jrAudioPro2 as the core and expanding from there. Hope is not a problem. I will install the beta release and test it while working on the skin

Thank you for the update

Tags