Repository navigation
Fix "time_t' different typedef on 32-bit /64-bit systems - #3787
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughTwo changes: (1) cast the masked ChangesInteger formatting and timestamp diagnostics
Alpine 32-bit CI
🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
7b23981 to
bee7244
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #3787 +/- ##
============================================
- Coverage 76.70% 76.66% -0.05%
============================================
Files 162 162
Lines 80697 80710 +13
============================================
- Hits 61900 61875 -25
- Misses 18797 18835 +38
🚀 New features to boost your workflow:
|
roshkhatri
left a comment
There was a problem hiding this comment.
Can you please add a daily test that runs on alpine 32 bit so we dont run into this issue again?
662affa to
a4b71c9
Compare
|
I found a relatively significant issue related to time_t. The underlying definition of time_t is implementation-dependent and may vary across different libc implementations, ABIs, and architectures, mainly due to the Y2038 transition. For example, existing code may assume: time_t to_timestamp; This works when time_t is defined as: typedef long time_t; which is traditionally true on i386 glibc. However, when enabling: #define _TIME_BITS 64 time_t may become: typedef long long time_t; On musl libc, many 32-bit architectures already use a 64-bit time_t by default. In such cases, using %ld becomes incorrect and may lead to undefined behavior. Using %lld is still not fully portable either, since the actual underlying type of time_t is platform-dependent. A safer portable approach would be something like: printf("%jd", (intmax_t)to_timestamp); This potentially has a fairly broad impact, especially on formatting, ABI compatibility, struct layouts, serialization, and cross-platform behavior, so I think we should discuss a proper compatibility/fix strategy. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/daily.yml:
- Line 1955: The skip-token used by the job test-alpine-32bit is mismatched: the
job checks for 'alpine32' in contains(github.event.inputs.skipjobs, 'alpine32')
but the workflow input defaults still expose 'alpine' and '32bit', causing
unexpected runs; fix by making the tokens consistent — either change the job
condition to check both 'alpine' and '32bit' (e.g., require both tokens or a
combined check) or update the workflow input default list to include the single
token 'alpine32' so contains(github.event.inputs.skipjobs, 'alpine32') behaves
as intended.
- Line 1987: The run lines dangerously interpolate user inputs unquoted
(test_args / cluster_test_args) into shell commands (runtest, runtest-moduleapi,
runtest-sentinel); change them to avoid shell injection by treating inputs as
data: set an env var using toJSON (e.g. TEST_ARGS: ${{
toJSON(github.event.inputs.test_args) }}) and in the run script parse that JSON
into a safe array (or read it as a single quoted argument) and then invoke the
commands with the array/quoted variable (e.g. ./runtest "${ARGS[@]}" or
./runtest "$TEST_ARGS") so inputs are properly escaped rather than interpolated
raw.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2cd0644c-784d-4855-8d77-c56c1a13f339
📒 Files selected for processing (3)
.github/workflows/daily.ymlsrc/fuzzer_command_generator.csrc/valkey-check-aof.c
✅ Files skipped from review due to trivial changes (1)
- src/fuzzer_command_generator.c
| run: apk add tcl procps tclx | ||
| - name: test | ||
| if: true && !contains(github.event.inputs.skiptests, 'valkey') | ||
| run: ./runtest ${{ github.event_name != 'pull_request' && '--accurate' || '' }} --failures-output test-failures/valkey.json --verbose --dump-logs ${{github.event.inputs.test_args}} |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
ls -la .github/workflows || true
sed -n '1950,2025p' .github/workflows/daily.ymlRepository: valkey-io/valkey
Length of output: 5743
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# find where test_args and cluster_test_args are defined in daily.yml
rg -n "test_args|cluster_test_args" .github/workflows/daily.ymlRepository: valkey-io/valkey
Length of output: 17049
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '1,220p' .github/workflows/daily.ymlRepository: valkey-io/valkey
Length of output: 10563
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "^(on:|workflow_dispatch:|workflow_call:|inputs:)" .github/workflows/daily.ymlRepository: valkey-io/valkey
Length of output: 66
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "workflow_dispatch:|workflow_call:" .github/workflows/daily.ymlRepository: valkey-io/valkey
Length of output: 104
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Show around workflow_dispatch/workflow_call blocks (guessed ranges)
# Extract first 400 lines around top for inputs
sed -n '220,520p' .github/workflows/daily.ymlRepository: valkey-io/valkey
Length of output: 16772
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '1975,2010p' .github/workflows/daily.ymlRepository: valkey-io/valkey
Length of output: 2088
Harden run: commands against workflow input shell injection in .github/workflows/daily.yml
test_args and cluster_test_args are user-controllable workflow inputs (workflow_dispatch.inputs.* / workflow_call.inputs.*) but are interpolated unquoted into shell commands (./runtest, ./runtest-moduleapi, ./runtest-sentinel), allowing crafted values with shell metacharacters to alter command execution.
Suggested hardening pattern
- name: test
if: true && !contains(github.event.inputs.skiptests, 'valkey')
- run: ./runtest ${{ github.event_name != 'pull_request' && '--accurate' || '' }} --failures-output test-failures/valkey.json --verbose --dump-logs ${{github.event.inputs.test_args}}
+ env:
+ EXTRA_TEST_ARGS: ${{ inputs.test_args || github.event.inputs.test_args || '' }}
+ run: |
+ read -r -a extra_args <<< "$EXTRA_TEST_ARGS"
+ ./runtest ${{ github.event_name != 'pull_request' && '--accurate' || '' }} \
+ --failures-output test-failures/valkey.json --verbose --dump-logs \
+ "${extra_args[@]}"
- name: module api test
if: true && !contains(github.event.inputs.skiptests, 'modules')
run: |
make -C tests/modules 32bit # the script below doesn't have an argument, we must build manually ahead of time
- CFLAGS='-Werror' ./runtest-moduleapi --failures-output test-failures/moduleapi.json --verbose --dump-logs ${{github.event.inputs.test_args}}
+ read -r -a extra_args <<< "${{ inputs.test_args || github.event.inputs.test_args || '' }}"
+ CFLAGS='-Werror' ./runtest-moduleapi --failures-output test-failures/moduleapi.json --verbose --dump-logs "${extra_args[@]}"
- name: sentinel tests
if: true && !contains(github.event.inputs.skiptests, 'sentinel')
- run: ./runtest-sentinel --failures-output test-failures/sentinel.json ${{github.event.inputs.cluster_test_args}}
+ env:
+ EXTRA_CLUSTER_TEST_ARGS: ${{ inputs.cluster_test_args || github.event.inputs.cluster_test_args || '' }}
+ run: |
+ read -r -a cluster_args <<< "$EXTRA_CLUSTER_TEST_ARGS"
+ ./runtest-sentinel --failures-output test-failures/sentinel.json \
+ "${cluster_args[@]}"🧰 Tools
🪛 zizmor (1.25.2)
[error] 1987-1987: code injection via template expansion (template-injection): may expand into attacker-controllable code
(template-injection)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/daily.yml at line 1987, The run lines dangerously
interpolate user inputs unquoted (test_args / cluster_test_args) into shell
commands (runtest, runtest-moduleapi, runtest-sentinel); change them to avoid
shell injection by treating inputs as data: set an env var using toJSON (e.g.
TEST_ARGS: ${{ toJSON(github.event.inputs.test_args) }}) and in the run script
parse that JSON into a safe array (or read it as a single quoted argument) and
then invoke the commands with the array/quoted variable (e.g. ./runtest
"${ARGS[@]}" or ./runtest "$TEST_ARGS") so inputs are properly escaped rather
than interpolated raw.
There was a problem hiding this comment.
@roshkhatri, understood — the shell injection pattern exists across all jobs in the workflow file and predates this PR, so it's indeed out of scope here. Would you like me to open a follow-up issue to track hardening the test_args / cluster_test_args interpolation across daily.yml?
The fix explicitly casts the computed lru_clock value to unsigned int before passing it to sdscatfmt(), matching the %u format specifier and preserving the intended 24-bit LRU clock value. The Alpine 32-bit build fails with -Werror=format because a few time_t values are printed with %ld. This assumes that time_t is always compatible with long, which is not portable across all 32-bit and 64-bit targets. In particular, 32-bit Linux environments may use a time_t representation that does not match long, causing format checking failures when warnings are treated as errors. Signed-off-by: chenshi <[email protected]>
301bfe8 to
20f305e
Compare
|
@roshkhatri
Assistance from official personnel is required !!! |
There was a problem hiding this comment.
The changes look good to me.
The test script uses docker to pull an image of version 3.23; is it necessary to modify it to the latest version
Yes we should change to latest for alpine.
Currently, executing a use case takes approximately 30 to 40 minutes. Is there something wrong with the way I wrote it? Is there a more efficient way?
They way it is written is correct, github runners container: dont have a field of -platform so this is correct, However, I think we should keep this test just as a smoke test for the crash we saw in try-valkey.
But it is also file to keep it as is, cuz it took 31 mins, which is quite similar to other jobs in the WF
https://github.com/valkey-io/valkey/actions/runs/26227227813/job/77177403146?pr=3787
| run: apk add tcl procps tclx | ||
| - name: test | ||
| if: true && !contains(github.event.inputs.skiptests, 'valkey') | ||
| run: ./runtest ${{ github.event_name != 'pull_request' && '--accurate' || '' }} --failures-output test-failures/valkey.json --verbose --dump-logs ${{github.event.inputs.test_args}} |
| -e SKIPTESTS \ | ||
| -e TEST_ARGS \ | ||
| -e CLUSTER_TEST_ARGS \ | ||
| i386/alpine:3.23 \ |
There was a problem hiding this comment.
We can change this to latest as, in this file we are also testing against alpine:latest for the other test.
| CLUSTER_TEST_ARGS: ${{ github.event.inputs.cluster_test_args }} | ||
| run: | | ||
| docker run --rm \ | ||
| --platform linux/386 \ |
There was a problem hiding this comment.
It takes times to build under emulation, so 30-40 mins should be okay
roshkhatri
left a comment
There was a problem hiding this comment.
I think we can change the alpine to latest and merge it.
Signed-off-by: chenshi <[email protected]>
Signed-off-by: chenshi <[email protected]>
Signed-off-by: chenshi <[email protected]>
done. |
enjoy-binbin
left a comment
There was a problem hiding this comment.
Thanks, i see the CI is also green now, it is good to go
@enjoy-binbin Please consider the issue of Y2038 from a global perspective. Thank you, In the future, our product will switch from Redis to Valkey, and the requirements for stability are quite high. thanks. |
|
Using |
) Fix valkey-io#3781 ## Description This PR fixes a crash on 32-bit Alpine 3.23 / time64 environments when starting `valkey-server` and generating the `INFO server` output. On 32-bit Alpine 3.23, `time_t` is 64-bit. In `genValkeyInfoString()`, the `lru_clock` field is formatted with `%u`, but the expression passed to `sdscatfmt()` was derived from `server.unixtime`, whose type is `time_t`. This can pass a 64-bit varargs argument to a formatter expecting an unsigned int-sized value. As a result, later varargs arguments may be read at the wrong offset, which can lead to a segmentation fault during startup. The fix explicitly casts the computed `lru_clock` value to `unsigned int` before passing it to `sdscatfmt()`, matching the `%u` format specifier and preserving the intended 24-bit LRU clo The Alpine 32-bit build fails with `-Werror=format` because a few `time_t` values are printed with `%ld`. This assumes that `time_t` is always compatible with `long`, which is not portable across all 32-bit and 64-bit targets. In particular, 32-bit Linux environments may use a `time_t` representation that does not match `long`, causing format checking failures when warnings are treated as errors. ## Root Cause The crash is caused by a varargs width mismatch on 32-bit time64 systems: ```c "lru_clock:%u\r\n", (server.unixtime / LRU_CLOCK_RESOLUTION) & LRU_CLOCK_MAX, ``` On 32-bit Alpine 3.23, server.unixtime is backed by 64-bit time_t, so the expression may be passed as a 64-bit value. Since %u expects an unsigned int, sdscatfmt() consumes only part of the argument and subsequent arguments can become misaligned. # Fix Cast the value passed for %u to unsigned int: server.c ```c (unsigned int)((server.unixtime / LRU_CLOCK_RESOLUTION) & LRU_CLOCK_MAX) ``` updates the affected `time_t` formatting sites to use `%jd` together with an explicit `(intmax_t)` cast. This keeps the output portable across architectures without changing the `time_t` ABI or making assumptions about its underlying typedef. # Test This PR also added a new daily CI "test-alpine-32bit" Signed-off-by: chenshi <[email protected]> Signed-off-by: Alon Arenberg <[email protected]>
Fix #3781 ## Description This PR fixes a crash on 32-bit Alpine 3.23 / time64 environments when starting `valkey-server` and generating the `INFO server` output. On 32-bit Alpine 3.23, `time_t` is 64-bit. In `genValkeyInfoString()`, the `lru_clock` field is formatted with `%u`, but the expression passed to `sdscatfmt()` was derived from `server.unixtime`, whose type is `time_t`. This can pass a 64-bit varargs argument to a formatter expecting an unsigned int-sized value. As a result, later varargs arguments may be read at the wrong offset, which can lead to a segmentation fault during startup. The fix explicitly casts the computed `lru_clock` value to `unsigned int` before passing it to `sdscatfmt()`, matching the `%u` format specifier and preserving the intended 24-bit LRU clo The Alpine 32-bit build fails with `-Werror=format` because a few `time_t` values are printed with `%ld`. This assumes that `time_t` is always compatible with `long`, which is not portable across all 32-bit and 64-bit targets. In particular, 32-bit Linux environments may use a `time_t` representation that does not match `long`, causing format checking failures when warnings are treated as errors. ## Root Cause The crash is caused by a varargs width mismatch on 32-bit time64 systems: ```c "lru_clock:%u\r\n", (server.unixtime / LRU_CLOCK_RESOLUTION) & LRU_CLOCK_MAX, ``` On 32-bit Alpine 3.23, server.unixtime is backed by 64-bit time_t, so the expression may be passed as a 64-bit value. Since %u expects an unsigned int, sdscatfmt() consumes only part of the argument and subsequent arguments can become misaligned. # Fix Cast the value passed for %u to unsigned int: server.c ```c (unsigned int)((server.unixtime / LRU_CLOCK_RESOLUTION) & LRU_CLOCK_MAX) ``` updates the affected `time_t` formatting sites to use `%jd` together with an explicit `(intmax_t)` cast. This keeps the output portable across architectures without changing the `time_t` ABI or making assumptions about its underlying typedef. # Test This PR also added a new daily CI "test-alpine-32bit" Signed-off-by: chenshi <[email protected]>
Use intmax_t and %jd for time_t values so 32-bit time64 builds do not fail under -Werror=format. (cherry picked from commit 8d3e6c3) Signed-off-by: chenshi <[email protected]> Signed-off-by: Sarthak Aggarwal <[email protected]>
Use intmax_t and %jd for time_t values so 32-bit time64 builds do not fail under -Werror=format. (cherry picked from commit 8d3e6c3) Signed-off-by: chenshi <[email protected]> Signed-off-by: Sarthak Aggarwal <[email protected]>
Use intmax_t and %jd for time_t values so 32-bit time64 builds do not fail under -Werror=format. (cherry picked from commit 8d3e6c3) Signed-off-by: chenshi <[email protected]> Signed-off-by: Sarthak Aggarwal <[email protected]>
Backport to 9.0: valkey-check-aof.c %jd fix and an adapted test-alpine-32bit CI job. server.c/fuzzer changes are not applicable to 9.0. (cherry picked from commit 8d3e6c3) Signed-off-by: chenshi <[email protected]> Signed-off-by: Roshan Khatri <[email protected]> Signed-off-by: Sarthak Aggarwal <[email protected]>
Use intmax_t and %jd for time_t values so 32-bit time64 builds do not fail under -Werror=format. (cherry picked from commit 8d3e6c3) Signed-off-by: chenshi <[email protected]> Signed-off-by: Sarthak Aggarwal <[email protected]>
Use intmax_t and %jd for time_t values so 32-bit time64 builds do not fail under -Werror=format. (cherry picked from commit 8d3e6c3) Signed-off-by: chenshi <[email protected]> Signed-off-by: Sarthak Aggarwal <[email protected]>
Use intmax_t and %jd for time_t values so 32-bit time64 builds do not fail under -Werror=format. (cherry picked from commit 8d3e6c3) Signed-off-by: chenshi <[email protected]> Signed-off-by: Sarthak Aggarwal <[email protected]>
Backport to 9.0: valkey-check-aof.c %jd fix and an adapted test-alpine-32bit CI job. server.c/fuzzer changes are not applicable to 9.0. (cherry picked from commit 8d3e6c3) Signed-off-by: chenshi <[email protected]> Signed-off-by: Roshan Khatri <[email protected]> Signed-off-by: Sarthak Aggarwal <[email protected]>
) Fix valkey-io#3781 ## Description This PR fixes a crash on 32-bit Alpine 3.23 / time64 environments when starting `valkey-server` and generating the `INFO server` output. On 32-bit Alpine 3.23, `time_t` is 64-bit. In `genValkeyInfoString()`, the `lru_clock` field is formatted with `%u`, but the expression passed to `sdscatfmt()` was derived from `server.unixtime`, whose type is `time_t`. This can pass a 64-bit varargs argument to a formatter expecting an unsigned int-sized value. As a result, later varargs arguments may be read at the wrong offset, which can lead to a segmentation fault during startup. The fix explicitly casts the computed `lru_clock` value to `unsigned int` before passing it to `sdscatfmt()`, matching the `%u` format specifier and preserving the intended 24-bit LRU clo The Alpine 32-bit build fails with `-Werror=format` because a few `time_t` values are printed with `%ld`. This assumes that `time_t` is always compatible with `long`, which is not portable across all 32-bit and 64-bit targets. In particular, 32-bit Linux environments may use a `time_t` representation that does not match `long`, causing format checking failures when warnings are treated as errors. ## Root Cause The crash is caused by a varargs width mismatch on 32-bit time64 systems: ```c "lru_clock:%u\r\n", (server.unixtime / LRU_CLOCK_RESOLUTION) & LRU_CLOCK_MAX, ``` On 32-bit Alpine 3.23, server.unixtime is backed by 64-bit time_t, so the expression may be passed as a 64-bit value. Since %u expects an unsigned int, sdscatfmt() consumes only part of the argument and subsequent arguments can become misaligned. # Fix Cast the value passed for %u to unsigned int: server.c ```c (unsigned int)((server.unixtime / LRU_CLOCK_RESOLUTION) & LRU_CLOCK_MAX) ``` updates the affected `time_t` formatting sites to use `%jd` together with an explicit `(intmax_t)` cast. This keeps the output portable across architectures without changing the `time_t` ABI or making assumptions about its underlying typedef. # Test This PR also added a new daily CI "test-alpine-32bit" Signed-off-by: chenshi <[email protected]> Signed-off-by: Alon Arenberg <[email protected]>
Fix #3781
Description
This PR fixes a crash on 32-bit Alpine 3.23 / time64 environments when starting
valkey-serverand generating theINFO serveroutput.On 32-bit Alpine 3.23,
time_tis 64-bit. IngenValkeyInfoString(), thelru_clockfield is formatted with%u, but the expression passed tosdscatfmt()was derived fromserver.unixtime, whose type istime_t. This can pass a 64-bit varargs argument to a formatter expecting an unsigned int-sized value. As a result, later varargs arguments may be read at the wrong offset, which can lead to a segmentation fault during startup.The fix explicitly casts the computed
lru_clockvalue tounsigned intbefore passing it tosdscatfmt(), matching the%uformat specifier and preserving the intended 24-bit LRU cloThe Alpine 32-bit build fails with
-Werror=formatbecause a fewtime_tvalues are printed with%ld. This assumes thattime_tis always compatible withlong, which is not portable across all 32-bit and 64-bit targets. In particular, 32-bit Linux environments may use atime_trepresentation that does not matchlong, causing format checking failures when warnings are treated as errors.Root Cause
The crash is caused by a varargs width mismatch on 32-bit time64 systems:
On 32-bit Alpine 3.23, server.unixtime is backed by 64-bit time_t, so the expression may be passed as a 64-bit value. Since %u expects an unsigned int, sdscatfmt() consumes only part of the argument and subsequent arguments can become misaligned.
Fix
Cast the value passed for %u to unsigned int:
server.c
updates the affected
time_tformatting sites to use%jdtogether with an explicit(intmax_t)cast. This keeps the output portable across architectures without changing thetime_tABI or making assumptions about its underlying typedef.src/valkey-check-aof.cto_timestampwith%jdand(intmax_t)to_timestampin all AOF truncate-to-timestamp messages.src/fuzzer_command_generator.cARG_TYPE_UNIX_TIMEvalues with%jdand(intmax_t)currentTime.Test
This PR also added a new daily CI "test-alpine-32bit"