T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/analyze_msq.py:211
- Finding
- Reversed AFR Safety Classification Can Produce Hazardous Tune Assessments<![CDATA[ ## Vulnerability Details **File Location**: `scripts/analyze_msq.py`, lines 211–217 **Vulnerability Type**: Incorrect safety-critical validation logic **Risk Level**: High ### Vulnerable Code ```python if min_afr < 10.0: issues.append(f"🚨 DANGER: AFR target goes as lean as {min_afr:.1f}:1 - risk of engine damage!") elif min_afr < 11.0: issues.append(f"⚠️ Very lean AFR target ({min_afr:.1f}:1) at high load - engine damage risk") if max_afr > 16.0: suggestions.append(f"ℹ️ AFR target reaches {max_afr:.1f}:1 - verify this is intentional (may be for decel)") ``` ### Technical Analysis For conventional gasoline air-fuel ratio values, a lower AFR number represents a richer mixture, while a higher number represents a leaner mixture. The analyzer reverses this relationship by describing AFR values below 10 or 11 as “lean.” The complementary check for AFR values above 16 is only recorded as an informational suggestion. Consequently, genuinely lean targets may not receive a warning of severity appropriate to the risk. A separate WOT heuristic may detect some unsafe targets, but it assumes that the bottom-right corner of the table represents high-load operation and does not reliably associate AFR values with their RPM and load axes. This is safety-critical validation logic: the analyzer is explicitly presented as suitable for reviewing a tune before engine startup or high-load testing. Incorrect classification may cause a user to misunderstand the direction of the fueling error. ### Attack Path 1. A user supplies an `.msq` file containing extremely rich or lean AFR target cells. 2. `parse_msq()` reads the AFR table and passes it to `analyze_afr_targets()`. 3. The function classifies very low AFR values as lean and treats globally high AFR values primarily as informational. 4. The generated report gives the user an incorrect or understated diagnosis. 5. The user relies on that report and changes the fuel map in the wrong direction, or proceed ...[truncated 1150 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Correct the AFR terminology and severity logic: - Low AFR values should be classified as rich. - High AFR values should be classified as lean. - Unsafe lean values under significant load should generate warnings or critical findings rather than informational notes. 2. Do not infer operating conditions solely from table position. Parse and use the AFR table's RPM and load-axis bins to classify each cell according to actual engine load and speed. 3. Distinguish operating contexts: - Idle and cruise. - Naturally aspirated high load. - Boosted high load. - Deceleration and fuel-cut regions. 4. Require engine and fuel context before making categorical safety claims. Relevant inputs include fuel type, forced-induction status, lambda/AFR representation, and sensor calibration. 5. Add unit tests covering: - AFR below 10 as very rich, not lean. - Safe WOT target ranges. - AFR above 14 under high load as potentially dangerous. - Lean deceleration cells that are intentional. - Tables whose axis ordering differs from the assumed orientation. 6. Clearly state when the analyzer cannot identify load context reliably and avoid presenting heuristic results as definitive safety approval. ]]>
