Public bug reported:
KCron, the "Scheduled Tasks" KCM of KDE (`kde-config-cron`), corrupts
non-ASCII text in the user's crontab. **Reading** the crontab only shows the
wrong text in the GUI; the file itself is damaged **when KCron saves it** —
from then on the crontab on disk contains the mis-decoded text.
Root cause is in `CommandLine::execute()` in `src/crontablib/ctcron.cpp`:
the output of `crontab(1)` is UTF-8, but it is decoded with `QLatin1String`,
i.e. byte-by-byte as Latin-1. KCron then re-encodes the resulting string as
UTF-8 when it writes the crontab back. Every non-ASCII character therefore
grows on each save: the Cyrillic `н` (`D0 BD`) is written back as
`C3 90 C2 BD` (4 bytes) after one save, 8 bytes after two, 16 bytes after
three (verified). ASCII text is unaffected, so the damage is easy to miss.
**This does not only damage Russian or other non-Latin comments — it also
rewrites the command lines of *enabled, actively scheduled cron jobs*.** As
soon as a job's executable path or its arguments contain a non-ASCII
character (for example `/home/user/скрипты/бэкап.sh`), the text stored in the
crontab no longer matches what is on disk. The consequences depend on what
exactly is corrupted: a corrupted **executable path** stops the job, because
cron cannot run a file that no longer exists under that name ("No such file
or directory"); corrupted **arguments or log paths** can leave the job
running but change its behaviour — it receives different arguments and
writes its output to a different or non-existent path. The same applies to
disabled jobs (`#\ ...`).
The corrupted file stays valid UTF-8 at every stage (verified), so editors
and `crontab -l` keep working and show mojibake — the loss is textual, not a
parse error. The mojibake is mechanically reversible by undoing the encoding
step, but KCron gives no warning and keeps no backup, so most users will not
notice before the job stops working correctly, and every further save grows
the damaged text.
Upstream fix (cherry-picked verbatim by this SRU):
* commit `4b525501ea791334c387ce03a0f47af2faeeece8`
"Use QString::fromUtf8 instead of QLatin1String"
https://invent.kde.org/kde/kcron/-/commit/4b525501ea791334c387ce03a0f47af2faeeece8
* KDE bug 494580: https://bugs.kde.org/show_bug.cgi?id=494580
Verified against upstream tags (pattern
`QLatin1String(process.readAllStandardOutput())`
vs `QString::fromUtf8(process.readAllStandardOutput())`): `v19.12.3`,
`v21.12.3`, `v23.08.5`, `v24.12.3`, `v25.08.1` and `v25.12.3` are affected;
`v26.04.0` and `v26.08.1` contain the fix.
Published Ubuntu versions carrying the defect (Launchpad API,
`getPublishedSources`, matched to the tags above): resolute
`4:25.12.3-0ubuntu1` (target of this SRU), questing `4:25.08.1-0ubuntu1`,
plucky `4:24.12.3-0ubuntu1`, noble `4:23.08.5-0ubuntu3`,
jammy `4:21.12.3-0ubuntu1`, focal `4:19.12.3-0ubuntu1`. Ubuntu devel and
tenacious already ship `4:26.08.1-0ubuntu1` (fixed).
[ Impact ]
* Saving a crontab that contains non-ASCII text (any language: Russian,
Greek, Chinese, Arabic, accented Latin, ...) from the KCron GUI corrupts
that text on disk. This is not a cosmetic problem in the comments only:
the *command of enabled cron jobs* is rewritten as well. The consequence
depends on what is corrupted: a corrupted executable path stops the job
(cron cannot run a file that no longer exists under that name), while
corrupted arguments or log paths can leave the job running but change
what it does — it gets different arguments and writes output elsewhere.
The damage is cumulative: every save roughly doubles the number of bytes
per affected character (verified: 2 -> 4 -> 8 -> 16 bytes for one
character), so the text degrades further with each edit. The file remains
valid UTF-8, so nothing warns the user.
* The GUI neither warns about this nor keeps a backup. The corrupted text
can be recovered by mechanically undoing the encoding step, but nothing
points the user at that, and the scheduled job has already misbehaved or
stopped in the meantime.
* The fix is a two-line cherry-pick of the upstream fix (commit
4b525501, KDE bug 494580) that replaces QLatin1String() decoding with
QString::fromUtf8() for the stdout/stderr of crontab(1). It changes no
logic other than the text decoding, and matches what upstream has
shipped since kcron 26.04.0.
[ Test Plan ]
* A) Automated, fully isolated (attached archive kcron-utf8-test.tar.gz).
Needs cmake, g++, Qt6/KF6 dev packages and kcron_25.12.3.orig.tar.xz from
the Ubuntu pool (README inside the archive lists the apt line).
tar -xzf kcron-utf8-test.tar.gz && cd kcron-utf8-test
./run.sh /path/to/kcron_25.12.3.orig.tar.xz
The harness replaces `crontab` with a stub that only reads/writes a file
inside the sandbox: no root, no real crontab is read or written.
Expected result (verified on 2026-11-10, overall exit code 0):
- step 1, pristine 25.12.3: FAIL (15 failed checks) — mojibake, changed
command bytes, corrupted schedules/comments;
- step 2, 25.12.3 + attached patch: PASS (0 failed checks).
* B) Manual GUI test — **mandatory in an isolated VM**, so that a mistake
cannot touch a real crontab. Sequential, so that the buggy and the fixed
package are compared on exactly the same input.
Preparation — do this once inside the VM:
1. Start from a clean crontab in the VM:
crontab -r 2>/dev/null || true
mkdir -p "$HOME/скрипты"
printf '#!/bin/sh\necho ok\n' > "$HOME/скрипты/тест.sh"
chmod +x "$HOME/скрипты/тест.sh"
( echo '# напоминание о еде'
echo "0 10 * * * $HOME/скрипты/тест.sh >> $HOME/журнал.log 2>&1" ) |
crontab -
2. Snapshot the *prepared* state (this is the reference for all later
comparisons, taken after the test job exists):
crontab -l > "$HOME/stateA.txt"
3. Sanity check of the comparator:
python3 verify_roundtrip.py "$HOME/stateA.txt"
"$HOME/stateA.txt" # PASS
Buggy version (4:25.12.3-0ubuntu1):
4. Open System Settings -> Scheduled Tasks (systemsettings kcm_cron),
select the job, and change the schedule minute from 0 to 5 — a test
data change that has no effect inside the VM — then press OK/Apply.
5. **Prove that the write happened; do not treat pressing the button as
proof.** Read the crontab back and confirm that the change you made in
the GUI is on disk:
crontab -l | grep -q '^5 10 \* \* \*' && echo "KCron wrote the
file"
If the line still reads `0 10 * * *`, KCron has not saved: repeat the
save (or use OK instead of Apply) and re-check before drawing any
conclusion from the comparison below.
6. Build the expected result of your own edit and compare against it
(stateB is stateA with only the minute you changed):
sed 's/^0 10 \* \* \*/5 10 * * */' "$HOME/stateA.txt" >
"$HOME/stateB.txt"
crontab -l > "$HOME/after1.txt"
python3 verify_roundtrip.py "$HOME/stateB.txt" "$HOME/after1.txt"
Expected on the buggy version: FAIL — the command path and the comment
text differ byte-wise (mojibake such as "напом..."); schedule fields
may still be intact and the file may still be valid UTF-8.
7. Repeat steps 4-6 with another safe change (minute 5 -> 7), proving the
write each time and comparing against the expected state: on the
buggy version the corruption grows (every non-ASCII character doubles
again).
Fixed version (package from -proposed):
8. Restore the prepared state: crontab "$HOME/stateA.txt"
9. Repeat steps 4-6 twice (minute 0 -> 5, then 5 -> 7), proving the write
on disk each time and comparing each result against the expected
state.
Expected: verify_roundtrip.py PASSES both times — valid UTF-8, no
mojibake, schedules equal to the values set in the GUI, commands,
arguments and paths byte-identical, comment text preserved, disabled
jobs preserved; the second result equals the first apart from KCron's
dated header line (idempotent).
What is compared, and what is not (KCron normalises on save):
- compared: UTF-8 validity, schedule fields (including the change made
in the GUI), command/argument/path bytes, comment text, disabled
jobs, idempotency of the second cycle;
- NOT required: byte-identity of the whole file — KCron rewrites the
schedule/command separator as a TAB, appends a trailing
"# File generated by KCron the <date>" line, and drops comments that
are separated from the following job by a blank line. The comparator
ignores the dated header line.
Isolation note: the KCM resolves `crontab` through PATH for **reading**
(verified — a stub first in PATH is called with `-l`). The **save** path
has not been verified, so a PATH stub must not be relied on for write
protection: run this test in an isolated VM.
Cleanup in the VM: crontab "$HOME/stateA.txt" (or crontab -r).
* C) Extra regression checks before marking verification-done:
- an ASCII-only crontab round-trips unchanged on both versions;
- disabled tasks written as `#\ ...` are preserved by the fixed version;
- System Settings -> Scheduled Tasks opens without KCM, KAuth or D-Bus
errors in the journal;
- the KCM still opens cleanly when the user has no crontab at all.
[ Where problems could occur ]
* The patch changes how *all* text returned by crontab(1) (both stdout and
stderr) is decoded, not just the job lines. If a crontab is stored in a
legacy single-byte encoding such as Latin-1 rather than UTF-8, the old
code interpreted those bytes as Latin-1 and re-encoded them as UTF-8 on
save — so the bytes already changed (the old code did not preserve a
Latin-1 crontab byte-for-byte either), but each character survived a
consistent interpretation. With the fix, bytes that are not valid UTF-8
are replaced by U+FFFD replacement characters, which is irreversible for
such a file. UTF-8 is the normal encoding of user data in modern Ubuntu
locales, so this should be rare, but a tester migrating a legacy-encoded
crontab could see a behaviour change here.
* Decoding of stderr changes too: non-ASCII error messages from crontab(1)
are now rendered as UTF-8 instead of Latin-1 mojibake. If any code path
matched on the exact stderr text, a match could change; in practice exit
codes are used, but this is the second place to look if a regression
shows up.
* If the cherry-pick landed in the wrong context the package would fail to
build; the attached source package has been built successfully with
dpkg-buildpackage and the resulting .so contains the fromUtf8 calls in
CommandLine::execute() (checked with objdump).
* Visible regression symptoms to watch for: mojibake reappearing after a
save, jobs disappearing or failing with "No such file or directory",
jobs running with different arguments or writing logs elsewhere,
comments being replaced, schedules being altered, or the KCM failing to
open. Any of these should be reported as a regression-update bug.
[ Other Info ]
* No autopkgtest is included: kcm_cron is a GUI KCM whose save path needs
a running session and a crontab tool, so an archive-level autopkgtest
cannot exercise the affected code. Per the SRU bug template the
equivalent reproduction is provided as an attached self-contained test
archive instead (see Test Plan A).
* Attachments with this report:
1. fix-utf8-crontab-output.patch — quilt patch, 2 lines, verbatim
cherry-pick of upstream 4b525501, DEP-3 headers
(Bug-Ubuntu: LP: #TODO — will be updated with this bug's number);
2. kcron-utf8-test.tar.gz — self-contained test (harness, synthetic
crontab, comparator, run.sh, README); needs no root and never
touches a real crontab; expected to fail on pristine 25.12.3 and
pass with the patch;
3. test-results.md — recorded output of running that archive
(15 failed checks on pristine 25.12.3, 0 with the patch).
The source package (kcron_25.12.3-0ubuntu1.1.dsc +
kcron_25.12.3-0ubuntu1.1.debian.tar.xz) and the debdiff against
4:25.12.3-0ubuntu1 will be attached in a follow-up comment together
with the updated patch carrying this bug's number.
* Proposed version: 4:25.12.3-0ubuntu1.1 (resolute). The same fix is
likely wanted for the other affected supported series (noble, jammy);
those are out of scope for this report and can be filed separately.
* Local test-build note (NOT part of the upload): the reference binary was
built with LTO disabled (-fno-lto) because GCC 13 on this machine hits
an internal compiler error when LTO temporary files live under a path
containing non-ASCII characters. The archive build is unaffected; the
patch itself contains no build-system changes.
** Affects: kcron (Ubuntu)
Importance: Undecided
Status: New
** Affects: kcron (Ubuntu Resolute)
Importance: Undecided
Status: New
--
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2173839
Title:
kcron: KCron corrupts non-ASCII UTF-8 text in the user crontab on
every save — comments and enabled job command paths
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/kcron/+bug/2173839/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs