Commit Graph
479 Commits
Author SHA1 Message Date
Jash 1759a22afe fix: keep a partial trigger message until its line ends instead of handling both halves refs #5856 2026-11-14 19:13:17 +05:30
Isaac Connor 55671fcd96 Merge pull request #5553 from AJ0070/5552-janus-pin-shm
perf: read the Janus pin from shared memory instead of running zmu
2026-11-12 19:52:58 -05:00
Isaac Connor 7a43d5a20b Merge pull request #5534 from AJ0070/5533-blob-skip-black
perf: skip black pixels eight at a time when looking for blobs
2026-11-12 19:50:58 -05:00
Isaac Connor e5de8d352b Merge pull request #5518 from AJ0070/5517-zms-zone-count
perf: count zones instead of building them when a monitor is loaded without zones
2026-11-12 19:48:26 -05:00
Isaac Connor 31ee44e611 Merge pull request #5604 from AJ0070/5603-dbqueue-drain
fix: keep the DB queue writing until stop() so rows queued at shutdown are saved
2026-11-12 08:33:37 -05:00
Isaac Connor 981a5127bd Merge pull request #5606 from AJ0070/5605-delete-storage-diskspace
fix: take a deleted event's DiskSpace off its Storage in the PHP delete
2026-11-12 08:32:39 -05:00
Isaac Connor 4647900ff0 Merge pull request #5608 from AJ0070/5607-jpeg-raw-any-width
perf: encode YUV420P jpegs of any width from the planes
2026-11-12 08:30:33 -05:00
Isaac Connor c7666dd297 Merge pull request #5612 from AJ0070/5611-privacy-mask-owner
fix: let the Monitor own its privacy mask image instead of delete[]ing its buffer
2026-11-12 08:25:31 -05:00
Jash 148bc3c2cd fix: let the Monitor own its privacy mask image instead of delete[]ing its buffer refs #5611 2026-11-12 10:22:12 +05:30
Jash 2c1fcb003a perf: encode YUV420P jpegs of any width from the planes refs #5607 2026-11-12 10:00:33 +05:30
Jash 3f635686a1 fix: take a deleted event's DiskSpace off its Storage in the PHP delete refs #5605 2026-11-12 09:49:11 +05:30
Jash 351f096974 fix: keep the DB queue writing until stop() so rows queued at shutdown are saved refs #5603 2026-11-12 09:41:22 +05:30
Jash 9ec9b43d62 perf: step polygon fills by density instead of testing every pixel refs #5599 2026-11-12 09:04:48 +05:30
Isaac Connor bff634b713 Merge pull request #5598 from connortechnology/fix/delta-nonaligned-width-sse-crash-master
fix: handle a non-block-aligned row width in Image::Delta
2026-11-11 22:10:52 -05:00
Isaac ConnorandClaude Opus 4.8 bb7204449b fix: handle a non-block-aligned row width in Image::Delta
The delta8_* helpers consume whole blocks per iteration (16 pixels for
the gray8 unrolled/SSE2/NEON variants, 4 pixels for the rgb32 ones). The
SSE2 and NEON variants require the pixel count to be an exact multiple of
that block: a shorter count wraps the loop counter past zero and runs off
the end of memory, and the unrolled C variants overrun by up to a block.

Since PR #4788 made Delta stride-aware it drives those helpers row by row
with the row width as the count. update_function_pointers() only falls
back to the scalar helpers when total pixels % 4 is non-zero, which does
not imply each row width is block-aligned. A monitor whose width is not a
multiple of 16 (e.g. 1366) therefore reaches sse2_delta8_gray8 with a
count of 1366 and zmc dies with SIGSEGV in that loop.

Run the block-aligned bulk of each row through the fast/SIMD helper and
finish the remaining tail pixels with the matching one-pixel-at-a-time
scalar helper.

tests/zm_image_delta.cpp exercises gray8 (widths 17 and 1366) and rgb32
(width 6) at counts that select the SIMD path; each reproduces the crash
on the unfixed code and verifies the per-pixel result on the fix.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-11 21:53:49 -05:00
Isaac Connor d34f26d14c Merge pull request #5538 from AJ0070/5537-daemon-check-once
perf: ask zmdc.pl whether ZoneMinder is running once a request
2026-11-11 21:49:14 -05:00
Isaac Connor e5572b9c19 Merge pull request #5492 from AJ0070/5491-passthrough-codec-tag
fix: drop input codec tags the output muxer rejects when copying video
2026-11-11 18:41:55 -05:00
Jash 53aaaa4d07 perf: scale a streamed frame straight from shared memory into a reused image instead of copying it first fixes #5585 2026-11-12 03:43:11 +05:30
Isaac ConnorandClaude Opus 5.5 c1aeb61bf2 fix: report who sent a fatal signal instead of a made-up fault address refs #5215
For a signal sent with kill(), raise() or sigqueue() rather than raised by
a fault, si_addr shares its storage with the sender's pid and uid, so the
crash report printed "unknown segfault code (signal code 0)" and a fault
address that was really those two numbers. The report now says
"Sent by process <pid> (uid <uid>)" and gives only the instruction
pointer for SI_USER, SI_QUEUE and, where defined, SI_TKILL. Reports of
real faults are unchanged; a test checks that a write to address 0x10
still reports that address.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:02:59 -05:00
Jash bb36f9b5ac perf: read the Janus pin from shared memory instead of running zmu fixes #5552 2026-11-12 00:27:25 +05:30
Jash 43ca621e7c fix: stop the fifo stream running the command thread loop inline fixes #5545 2026-11-11 23:09:51 +05:30
Jash 3f1907960a perf: ask zmdc.pl whether ZoneMinder is running once a request fixes #5537 2026-11-11 19:49:28 +05:30
Jash 13e16a2b2c perf: skip black pixels eight at a time when looking for blobs fixes #5533 2026-11-11 19:17:43 +05:30
Jash 3abf32344a perf: count zones instead of building them when a monitor is loaded without zones fixes #5517 2026-11-11 12:07:53 +05:30
Jash 1b815b13c5 test: initialize ffmpeg before looking up muxers in the codec tag test refs #5491 2026-11-11 09:23:25 +05:30
Isaac Connor cdf6ce1d2d Merge pull request #5485 from AJ0070/av1-leb128-shift
fix: parse AV1 LEB128 sizes without shifting an int past its width
2026-11-10 22:29:00 -05:00
Isaac Connor 9deb4663c0 Merge pull request #5489 from AJ0070/5488-jpeg-raw-yuv
perf: encode YUV420P JPEGs straight from the planes
2026-11-10 22:22:58 -05:00
Isaac Connor 0d666af336 Merge pull request #5498 from connortechnology/fix/5215-signal-safe-crash-handler
fix: make the crash signal handler async-signal-safe (GHSA/#5215)
2026-11-10 22:22:33 -05:00
Isaac ConnorandClaude Opus 5.5 6fd53c3db2 fix: make a crashing process non-dumpable when ZM_DUMP_CORES is off refs #5215
A zero RLIMIT_CORE stops the kernel writing a core file, but when
core_pattern pipes to a program such as systemd-coredump or apport the
kernel hands it the dump anyway and leaves the limit to that program.
With ZM_DUMP_CORES off, the die handler now also calls
prctl(PR_SET_DUMPABLE, 0) when it starts reporting, so the kernel skips
the dump unless fs.suid_dumpable is 2, in which case the limit still
applies. It is done only at crash time because it also stops ptrace and
makes root the owner of the process's /proc files. Linux only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 20:58:37 -05:00
Isaac Connor d32b3d4752 Merge pull request #5069 from AJ0070/fix/4727-clear-logs
fix: clear all logs when no rows are selected
2026-11-10 19:14:43 -05:00
Isaac ConnorandClaude Opus 5.5 dab97e4730 test: fail crash handler tests the report timeout had to end refs #5215
The die handler's 5 second report timeout replaced the child's alarm()
watchdog and ends a stuck report on the original signal, so a test whose
report stalled still passed. run_crashing_child() now waits in the parent
with its own deadline, 4 seconds by default, and kills the child and
fails the test once it passes. The blocked-stderr test, which is meant to
reach the timeout, gets 8 seconds; the other-thread test, which ends
through its 3 second wait, gets 4.5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 19:07:01 -05:00
Isaac Connor 16e4174dbd Merge pull request #5487 from AJ0070/5486-zone-bbox-memset
perf: stop zeroing the whole zone bounding box every frame
2026-11-10 18:44:22 -05:00
Isaac ConnorandClaude Opus 5.5 9076791f06 fix: leave no core dump from the die handler when ZM_DUMP_CORES is off refs #5215
The die handler is installed only when ZM_DUMP_CORES is off. It used to end
the process with exit(), so no core was written; it now re-raises the fault
with the default action, which dumps core wherever the core size limit
allows. zmSetDefaultDieHandler() now lowers the soft RLIMIT_CORE to 0 in
that case. The hard limit is left as it was, and with ZM_DUMP_CORES on
nothing changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 18:09:29 -05:00
Isaac ConnorandClaude Opus 5.5 c42e367215 fix: keep SIGPIPE from cutting the crash report short refs #5215
Only zms handles SIGPIPE; in zmc, zma and zmu it is fatal. A crash report
written to a stderr pipe whose reader had gone raised SIGPIPE, which killed
the process before the report reached the log file or syslog and replaced
the fault as the cause of death. SIGPIPE is now blocked while the die
handler runs, so the write fails with EPIPE and the report goes on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 18:09:17 -05:00
Isaac ConnorandClaude Opus 5.5 84abc12171 fix: end a crash report that blocks on the fault it reports refs #5215
A write in the die handler that never completes, such as to a stderr pipe
nobody reads when a daemon is run by hand, left the process hung with the
fault never reaching zmdc. The handler now sets a 5 second alarm when it
starts reporting; if it fires, a SIGALRM handler ends the process on the
signal that was being reported. alarm() and sigaction() are
async-signal-safe and nothing else in ZoneMinder uses SIGALRM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 18:08:53 -05:00
Isaac ConnorandClaude Opus 5.5 ac331f19d6 fix: send the crash report to syslog without blocking or a stale socket refs #5215
- The crash socket was blocking, so a full syslog queue could leave the
  crashed process waiting in send() instead of dying. It is now non-blocking
  and a line that does not fit is dropped.
- zmSetCrashSyslog() rewrote the ident in place while another thread could
  be reading it in the handler. It now publishes a new, never-modified
  target (socket path and ident) through an atomic pointer.
- The socket was connected once, so a syslog daemon that restarted and made
  a new socket no longer got reports. It is left unconnected and each line
  is sent with sendto() to the stored path.
- The default path was /dev/log everywhere; it is now _PATH_LOG, which is
  /var/run/syslog on macOS and /var/run/log on FreeBSD.

Tests: the fork helper fails a test whose child the watchdog had to kill;
new cases cover a recreated syslog socket and a full syslog queue (filled
from several senders, as Linux caps what one sender may queue). The
worker-thread overflow test accepts SIGBUS, which is what macOS raises.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 08:18:56 -05:00
Isaac ConnorandClaude Opus 5.5 894c0a5189 fix: keep the crash report signal-safe across rotation, threads and syslog refs #5215
Review follow-ups to the async-signal-safe die handler:

- The log file descriptor the handler wrote to could be closed by a log
  rotation after the handler loaded it, and its number reused by an
  unrelated file or socket. zmSetCrashLogFile() now keeps one descriptor
  that is never closed and dup2()s each new log file onto it, so it only
  ever refers to a log file.
- Lines were formatted with snprintf(), which is not async-signal-safe. A
  small fixed-buffer CrashLine appends strings, decimals and hex instead.
- glibc backtrace() loads libgcc_s on first use, which allocates. It is now
  called once when the handler is installed, and the comment that called it
  safe is corrected.
- zmdc points daemons' stderr at /dev/null, so with file logging off the
  report went nowhere. The handler now also sends each line to syslog over
  its own datagram socket, connected by zmSetCrashSyslog() when the Logger
  opens syslog, without calling syslog(3).
- A second signal arriving during the report was blocked when re-raised, so
  the process exited 255 instead of dying of it. Both paths now go through
  die_of(), which unblocks the signal.
- The shared volatile flag did not stop two threads that fault together from
  both reporting. A lock-free atomic_flag picks the reporting thread; a fault
  on another thread waits for it to end the process, and a fault inside the
  handler on the same thread dies at once.
- sigaltstack() only covers the calling thread. zmSetThreadAltStack() gives
  a thread its own stack, freed when it exits; main, the decoder and the
  analysis threads call it.

Tests fork a child per case: report formatting, the rotated log file, the
syslog datagram, a second signal mid-report, a fault on another thread
mid-report, and a stack overflow on a worker thread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 23:29:29 -05:00
Isaac ConnorandClaude Opus 4.8 04f097b9c0 fix: surface export copy failures and stop output accumulating fixes #5085
exportEvents() copies each event file with exec($cmd, $output, $return)
and only put $return into a ZM\Debug line, so a failed cp never reached
the user and the export still handed back an archive missing files - the
"fails silently" half of #5074. $output was also never reset between
iterations, and exec() appends to a non-empty array, so that Debug line
accumulated every line of output from every file in the export.

Reset $output before each copy, and on a non-zero return log a ZM\Error
and mark the export failed; after the loop, return false when any copy
failed so ajax/event.php reports "Export Failed" instead of serving an
incomplete archive, matching how the tar/zip step already handles its
own exec() status.

tests/php/test_export_copy_failure.php extracts the exportEvents() body
from the real source and checks the reset and the failure handling are
present; it fails against the pre-fix source.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-08 18:07:30 -05:00
Isaac ConnorandClaude Opus 4.8 d071d9948a fix: make the crash signal handler async-signal-safe fixes #5215
zm_die_handler logged through Error()/Fatal() and, on the second signal,
called Fatal() -> logPrint(), which from inside the handler stopped the
database queue, closed the MySQL handle, deleted the Logger and called
exit(): it joined and freed objects the decoder, analysis and stream
threads were still using, ran atexit handlers and static destructors (the
libcrypto/MariaDB signal-unsafe-call floods seen under ThreadSanitizer),
and could deadlock on the log mutex. The crash report it wrote to the Logs
table was sometimes cut short or lost, and the process could hang instead
of exiting.

Emit the crash report (signal, fault reason, fault and instruction
address, backtrace) with async-signal-safe write(2) only, to stderr and,
when open, the per-process log file, then restore the default disposition
and re-raise the signal so the process dies of the actual fault and can
leave a core dump. Nothing touches the database, the log queue or the
Logger from the handler.

- The Logger publishes its log-file descriptor in zm_crash_log_fd when it
  opens the file and clears it on close, so the handler can write to the
  log file without going through the Logger.
- The glibc path uses backtrace_symbols_fd(), which does not allocate,
  instead of backtrace_symbols(); the libunwind path writes fixed buffers.
- Install the handler on a dedicated sigaltstack so a stack-overflow fault
  can still be reported, and guard against faulting again while handling.

The crash detail now lands in the log file and syslog rather than the Logs
table; zmdc restarts the daemon and records the abnormal exit.

tests/zm_signal.cpp forks a child, installs the handler, raises SIGSEGV
and checks the process dies of the signal rather than exiting from the
handler, and that the report reached stderr and the published log fd.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-08 17:57:05 -05:00
Jash 8a5a75b587 fix: drop input codec tags the output muxer rejects when copying video fixes #5491 2026-11-08 20:23:58 +05:30
Jash 1352a44c7d perf: encode YUV420P jpegs from the planes with libjpeg raw data input, fixes #5488 2026-11-08 16:59:09 +05:30
Jash 451214a7b9 perf: zero only the zone pixels std_alarmedpixels does not write instead of every bbox row, fixes #5486 2026-11-08 16:07:03 +05:30
Jash c15eefbfdc fix: parse AV1 LEB128 sizes in 64 bits instead of shifting an int past its width, fixes #5484 2026-11-08 15:59:43 +05:30
Jash 62e8d24e29 fix: port clear all logs to the log panel and report server refusals, refs #4727 2026-11-08 15:01:42 +05:30
Jash 0f5c823378 Merge remote-tracking branch 'upstream/master' into fix/4727-clear-logs
# Conflicts:
#	web/skins/classic/views/js/log.js
#	web/skins/classic/views/js/log.js.php
#	web/skins/classic/views/log.php
2026-11-08 14:54:24 +05:30
Isaac ConnorandClaude Opus 4.8 bf04cfe04c fix: refuse a path-traversal export name in exportEvents/downloadEvents refs GHSA-9hf5-jpww-rvpp
The export-generation path sanitized the user-supplied export directory name with
preg_replace('/[^\w\-.]/', '', ...), a whitelist that keeps dots, so a bare '..'
survived and $export_root became the parent of the export root. exportEvents()
then chmod'd, wrote into, and tarred that parent, and the archive was downloadable
through the safeExportComponent() read guard because it genuinely sat in the
exports dir. downloadEvents() had the same shape via DIR_EXPORTS_DOWNLOAD
(refs GHSA-72h2-rvhv-wr5g).

These are residual siblings of GHSA-fvx4-86xp-9v22, which hardened the download/
read views but left the write path. Refuse a '.'/'..' component in exportEvents(),
and route downloadEvents()'s name through the existing safeExportComponent().

Add tests/php/test_export_path_traversal.php.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-07 10:54:46 -05:00
Isaac ConnorandClaude Opus 4.8 71cae39ed9 fix: pass a field allow-list at every API buildFilter call site refs GHSA-xqfr-6v9x-cvwc
Follow-up to the numeric field-name guard. FilterComponent::buildFilter() takes
an optional $validFields allow-list, but only EventsController's search index
and MonitorsController (via qualifyFields) used it; the other index/search/
consoleEvents call sites passed none, so a field name was checked only by the
character class, not against a known column set.

Pass array_keys($this->Model->schema()) - the pattern EventsController already
uses - at the remaining sites across Configs, EventData, Events (three), Frames,
Groups, ServerStats, Snapshots, Storage, Tags and UserPreference, so a field
must be a real column of the queried model and an unknown field is a 400 rather
than a MySQL 500. The injection itself is already closed by the numeric
field-name guard; this is defense in depth and consistent error handling.

ServerStatsController's commented-out permission check is left as-is (clients
need the data to render monitors); only the allow-list is added there.

Add tests/php/test_api_filter_fields_enforced.php.

Reported by arpitjain099.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-07 10:27:31 -05:00
Isaac ConnorandClaude Opus 4.8 71996d18b6 fix: reject all-digit API filter field names in FilterComponent refs GHSA-xqfr-6v9x-cvwc
A named parameter written `0:<payload>` reaches FilterComponent::buildFilter()
as an integer array key, and the field regex `[a-z0-9.]+` matched the all-digit
name, so `$conditions["0"] = $value` cast the key to an int. CakePHP 2.x renders
an integer-keyed condition as a raw, unescaped SQL fragment, so the value went
into the WHERE clause verbatim (UNION exfiltration, ACL bypass via a trailing
comment, blind boolean oracle) at the index() call sites that pass no
$validFields allow-list.

Refuse an all-digit field name in buildFilter(), so every key that reaches
$conditions contains a letter or a dot and stays a string key that CakePHP
quotes. Add tests/php/test_api_filter_numeric_field.php.

Reported by arpitjain099.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-07 10:01:11 -05:00
Isaac Connor 05081ce635 Merge pull request #5322 from connortechnology/5186-zms-ui-next-event
fix: let the UI tell zms which event is next/prev for gapless playback
2026-11-06 18:49:12 -05:00
Isaac ConnorandClaude Opus 5.5 2d4605ef11 fix: look up neighbours again while zms is paused refs #4186
When the next event the page sent has been deleted, zms stops at the end of
the current event. The page only asked again about a 0 boundary, so it kept the
deleted neighbour and zms stayed paused. Ask again every BOUNDARY_REFRESH_MS
while zms reports paused; a different answer is sent and resumes it through
HintResumes. A user's pause is unaffected, since zms only resumes after
stopping at the end of the filter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 20:18:13 -05:00