← Back to Pull requests

zip: Fix crashes on buggy zip output #509

Merged
cwendling merged 1 files (13 lines) on Jan 31, 2024 13:08 UTC
View on GitHub
cwendling cwendling commented on Jan 24, 2024 22:55 UTC
Author

Fix crash if the zip command emits a line starting with one of 'd?-' yet having less than 8 fields in it, or if the date field is malformed.

Small fixed for not doing nasty things if unzip doesn't output what we expect.

Testing

Real test should be that it doesn't break anything, as that's what most important (although it's unused for people having one of the 7z, which is used in priority)

Convoluted test is to check what happens with random unexpected output from unzip.

What I did to test unexpected output was add a dummy unzip to my PATH, and get that to emit output good enough for the code to try and parse it, and bad enough to trigger issues.
For example, use this script in your PATH:
<details>
<summary><code>~/.local/bin/unzip</code></summary>

#!/bin/sh

cat << EOF
# legit stuff
? x x 123 A X 20240123.223500 foo1
d x x 456 B X 20240123.223600 foo2
- x x 789 C X 20240123.223789 foo3
# less legit stuff
? foo4
? x x 789 C X x foo5
# more legit stuff to make sure we keep on reading
- x x 789 C X 20240123.223789 foo6
EOF

</details>

You also need not to have any 7z, or disable ZIP handling by 7z as it takes precedence:

diff --git a/src/fr-command-7z.c b/src/fr-command-7z.c
index 7b40d5e..5d385a3 100644
--- a/src/fr-command-7z.c
+++ b/src/fr-command-7z.c
@@ -598,7 +598,7 @@ const char *sevenz_mime_types[] = { "application/epub+zip",
 				    "application/x-ms-dos-executable",
 				    "application/x-ms-wim",
 				    "application/x-rar",
-				    "application/zip", /* zip always at the end and the number of */
+				    //"application/zip", /* zip always at the end and the number of */
 				    NULL };            /* place in fr_command_7z_get_mime_types   */
 
 static const char **

Normally this should result in a clean Valgrind report (well, for memory errors that is, there's probably a lot of unrelated leaks to be found).

Diff: 13 lines (+12 / -1) across 1 files Reviewer: raveit65 Review duration: 9493m
All Vouch review confidence checks passed
Residual risk 0.10 = Change Risk (0.19) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.19 · 13 lines diff across 1 files
0.19
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth shallow_review_depth
0.344
Diff Size diff_size
0.158
Real PR Conversation Timeline
1 item
"Review active on #509"
general weight: 0.35
Reviewers
Assignees
cwendling cwendling
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 18.8% (LOW) · Higher = larger blast radius
18.8%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 10% · Safe to merge
10%