Skip to content

when certain invalid DDP messages are received, all LEDs switched off #5380

Closed

Description

@folkertvanheusden

What happened?

Not very critical, but I noticed that WLED is sensitive for invalid/corrupted DDP packets.

To Reproduce Bug

e.g.:

21:03:53.226765 IP (tos 0x0, ttl 255, id 293, offset 0, flags [none], proto UDP (17), length 124)
    10.208.2.7.4048 > 10.208.3.255.4048: UDP, length 96
    0x0000:  4500 007c 0125 0000 ff11 9ea6 0ad0 0207  E..|.%..........
    0x0010:  0ad0 03ff 0fd0 0fd0 0068 1133 4108 0bfb  .........h.3A...
    0x0020:  0000 0000 0056 7b22 7374 6174 7573 223a  .....V{"status":
    0x0030:  207b 2022 6d61 6e22 3a20 2277 7777 2e6b  .{."man":."www.k
    0x0040:  6f6d 7075 7469 6c6f 2e6e 6c22 2c20 226d  omputilo.nl",."m
    0x0050:  6f64 223a 2022 4c69 6768 7462 6f78 2044  od":."Lightbox.D
    0x0060:  4450 2073 6572 7665 7222 2c20 2276 6572  DP.server",."ver
    0x0070:  223a 2022 302e 3122 207d 207d            ":."0.1".}.}

test.pcap.zip

Expected Behavior

Ignore invalid packets

Install Method

Binary from WLED.me

What version of WLED?

any version

Which microcontroller/board are you seeing the problem on?

ESP8266

Relevant log/trace output

I tried running a `WLED_DEBUG` version but that doesn't give extra output in the console.

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. DedeHai commented on Feb 19, 2026

    @DedeHai
    Collaborator

    @coderabbitai please elaborate if this is a bug or a feature

  2. coderabbitai commented on Feb 19, 2026

    @coderabbitai
    Contributor
    🧩 Analysis chain

    🏁 Script executed:

    #!/bin/bash
    # Fetch details of issue `#5380` from wled/WLED repository
    gh issue view 5380 --repo wled/WLED --json title,body,labels,comments --jq '{title: .title, body: .body, labels: [.labels[].name], comments: [.comments[] | {author: .author.login, body: .body}]}'
    

    Length of output: 1681


    @DedeHai, this is definitely a bug, not a feature. Here's why:

    Why This is a Bug:

    1. 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.

    2. 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.

    3. 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.

    4. 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.

  3. blazoncek commented on Feb 19, 2026

    @blazoncek
    Contributor

    @coderabbitai how do you determine if a packet is valid and in DDP format?

  4. coderabbitai commented on Feb 19, 2026

    @coderabbitai
    Contributor
    🧩 Analysis chain

    🏁 Script executed:

    #!/bin/bash
    # Search for DDP packet handling code
    echo "=== Searching for DDP protocol handling ==="
    rg -n "DDP" --type cpp -C 5
    
    echo -e "\n=== Looking for DDP packet structure definitions ==="
    rg -n "struct.*[Dd][Dd][Pp]|#define.*DDP" --type cpp --type c -C 3
    
    echo -e "\n=== Searching for DDP header validation ==="
    rg -n "DDP.*header|header.*DDP|0x44.*0x44|DDP_FLAGS|DDP_ID" --type cpp -C 5
    

    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)

    if (len < 10 + offset) return; // DDP header is 10 bytes

    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:

    Byte 0:     flags (version, push, query, reply, storage, timecode)
    Byte 1:     sequenceNum
    Byte 2:     dataType (RGB24=0x0B, RGBW32=0x1B)
    Byte 3:     destination (DISPLAY=1, CONFIG=250, STATUS=251)
    Bytes 4-7:  channelOffset (32-bit, MSB first)
    Bytes 8-9:  dataLen (16-bit, MSB first)
    

    4. Data Length Validation (ws.cpp)

    size_t ddpDataLen = (data[8+offset] << 8) | data[9+offset];
    if ((flags & DDP_TIMECODE_FLAG)) ddpDataLen += 4;
    if (len < (10 + offset + ddpDataLen)) return;

    Validates that the actual packet size matches the declared data length.

    5. Bounds Checking (e131.cpp)

    unsigned maxDataIndex = c + numLeds * ddpChannelsPerLed;
    if (maxDataIndex > dataLen) {
      DEBUG_PRINTLN(F("DDP packet data bounds exceeded, rejecting."));
      return;
    }

    Missing Validation (Potential Issue for #5380)

    The current implementation does NOT validate:

    1. Protocol Version: Should check (flags & DDP_FLAGS1_VER) == DDP_FLAGS1_VER1 (version 1 = 0x40)
    2. Data Type: Should verify dataType is valid (DDP_TYPE_RGB24 or DDP_TYPE_RGBW32)
    3. Destination ID: Should check if destination is a recognized value (1, 250, or 251)
    4. Flag Combinations: Should validate flag combinations are sensible

    Recommended Validation Logic

    For a robust DDP packet validator:

    bool isValidDDPPacket(const uint8_t* data, size_t len) {
      // 1. Minimum size
      if (len < 10) return false;
      
      // 2. Check version
      uint8_t flags = data[0];
      if ((flags & DDP_FLAGS1_VER) != DDP_FLAGS1_VER1) return false;
      
      // 3. Check data type
      uint8_t dataType = data[2];
      if (dataType != DDP_TYPE_RGB24 && dataType != DDP_TYPE_RGBW32) return false;
      
      // 4. Check destination
      uint8_t dest = data[3];
      if (dest != DDP_ID_DISPLAY && dest != DDP_ID_CONFIG && dest != DDP_ID_STATUS) return false;
      
      // 5. Validate data length
      uint16_t dataLen = (data[8] << 8) | data[9];
      uint16_t expectedLen = 10 + dataLen;
      if (flags & DDP_TIMECODE_FLAG) expectedLen += 4;
      if (len < expectedLen) return false;
      
      return true;
    }

    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.
    
  5. DedeHai commented on Feb 19, 2026

    @DedeHai
    Collaborator

    @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

  6. coderabbitai commented on Feb 19, 2026

    @coderabbitai
    Contributor
    🧩 Analysis chain

    🏁 Script executed:

    #!/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
    

    Length of output: 15797


    🏁 Script executed:

    #!/bin/bash
    # Find UDP listener initialization
    rg -n "void.*init.*udp|initUdp|setupUdp" --type cpp -B 3 -A 30
    

    Length of output: 0


    🏁 Script executed:

    #!/bin/bash
    # Look for where DDP packets come in via UDP vs WebSocket
    fd -e cpp -e h | xargs rg -l "DDP_DEFAULT_PORT|4048"
    

    Length of output: 135


    🏁 Script executed:

    #!/bin/bash
    # Read the const.h file for DDP definitions
    cat wled00/src/dependencies/e131/ESPAsyncE131.h | grep -A 30 "DDP"
    

    Length of output: 3138


    🏁 Script executed:

    #!/bin/bash
    # Read the ESPAsyncE131.cpp to see how DDP UDP packets are received
    cat wled00/src/dependencies/e131/ESPAsyncE131.cpp
    

    Length of output: 3996


    🏁 Script executed:

    #!/bin/bash
    # Also check DDP flag definitions
    rg -n "DDP_FLAGS1_VER|0x40|DDP.*VER" --type cpp --type h -B 2 -A 2
    

    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:

    41 08 0b fb 00 00 00 00 00 56 7b 22 73 74 61 74 75 73 22 3a ...
    

    DDP Header Parsing (10 bytes)

    Byte-by-byte breakdown:

    Offset Value Field Meaning
    0 0x41 flags 0x40 (DDP_FLAGS1_VER1) + 0x01 (DDP_PUSH_FLAG)
    1 0x08 sequenceNum Sequence number 8
    2 0x0B dataType DDP_TYPE_RGB24 (RGB, 3 channels)
    3 0xFB destination 251 = DDP_ID_STATUS ⚠️
    4-7 0x00000000 channelOffset Offset = 0
    8-9 0x0056 dataLen 86 bytes of data
    10+ 0x7B... data JSON text: {"status":...

    Execution Flow

    1. UDP Reception (ESPAsyncE131.cpp)

    void ESPAsyncE131::parsePacket(AsyncUDPPacket _packet) {
      // Try E1.31 - fails (not ACN_ID)
      // Try Art-Net - fails (not ART_ID)
      
      if (error && _packet.localPort() == DDP_DEFAULT_PORT) {
        error = false;
        protocol = P_DDP;  // ✓ Recognized as DDP
      }
      
      _callback(sbuff, _packet.remoteIP(), P_DDP);
    }

    2. Protocol Dispatch (e131.cpp:handleE131Packet)

    void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol) {
      if (protocol == P_DDP) {
        realtimeIP = clientIP;
        handleDDPPacket(p);  // ✓ Forwarded to DDP handler
        return;
      }
    }

    3. DDP Processing (e131.cpp:handleDDPPacket)

    static void handleDDPPacket(e131_packet_t* p) {
      // Read header fields
      uint8_t flags = p->flags;           // = 0x41
      uint8_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 LED
      unsigned ddpChannelsPerLed = ((dataType & 0b00111000)>>3 == 0b011) ? 4 : 3;
      // = 3 (RGB)
      
      // Calculate LED range
      uint32_t start = htonl(p->channelOffset) / ddpChannelsPerLed;  // = 0/3 = 0
      unsigned stop = start + dataLen / ddpChannelsPerLed;            // = 0 + 86/3 = 28
      
      uint8_t* data = p->data;  // Points to JSON: 0x7B 0x22 0x73...
      unsigned c = 0;  // No timecode
      
      // Bounds check
      unsigned numLeds = stop - start;                    // = 28
      unsigned maxDataIndex = c + numLeds * ddpChannelsPerLed;  // = 0 + 28*3 = 84
      if (maxDataIndex > dataLen) {  // 84 > 86? NO
        return;  // ✗ 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;  // = true
      if (push) {
        e131NewData = true;  // ✓ Triggers LED update
      }
    }

    Why LEDs Turn Off

    The issue occurs because:

    1. 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
    2. 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
    3. 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
    4. 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.
    
  7. blazoncek commented on Feb 19, 2026

    @blazoncek
    Contributor

    @coderabbitai here's my thought:

    1. 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) ...
    2. is reasonable and mandatory (though larger packets are the ones causing most issues)
    3. 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)
    4. what are the "sensible flags"?
  8. coderabbitai commented on Feb 19, 2026

    @coderabbitai
    Contributor
    🧩 Analysis chain

    🏁 Script executed:

    #!/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:

    static void handleDDPPacket(e131_packet_t* p) {
      uint8_t dataType = p->dataType;
      
      // Reject if dataType is not RGB24 or RGBW32
      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 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.
    
  9. blazoncek commented on Feb 19, 2026

    @blazoncek
    Contributor

    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.

  10. softhack007 commented on Feb 19, 2026

    @softhack007
    Member

    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

    @coderabbitai: I'm not sure about the DDP specification:

    • is the "destination" field part of each DDP packet?
    • Does our WLED "Network output" DDP format properly set data type and destination?
  11. coderabbitai commented on Feb 19, 2026

    @coderabbitai
    Contributor
    🧩 Analysis chain

    🏁 Script executed:

    #!/bin/bash
    # Read the DDP header structure definition
    echo "=== DDP Header Structure ==="
    cat wled00/src/dependencies/e131/ESPAsyncE131.h | grep -A 60 "struct e131_packet_t"
    
    echo -e "\n=== DDP Constants ==="
    cat wled00/src/dependencies/e131/ESPAsyncE131.h | grep "DDP_" | head -30
    
    echo -e "\n=== WLED's Network Output DDP implementation ==="
    cat wled00/bus_manager.cpp | sed -n '690,750p'
    

    Length of output: 2713


    🏁 Script executed:

    #!/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:

    struct { //DDP Header
      uint8_t flags;           // Byte 0
      uint8_t sequenceNum;     // Byte 1
      uint8_t dataType;        // Byte 2
      uint8_t destination;     // Byte 3 ← HERE
      uint32_t channelOffset;  // Bytes 4-7
      uint16_t dataLen;        // Bytes 8-9
      uint8_t data[1];         // Byte 10+
    } __attribute__((packed));

    The valid destination values (defined in udp.cpp):

    `#define` DDP_ID_DISPLAY 1    // 0x01 - LED display data
    `#define` DDP_ID_CONFIG 250   // 0xFA - Configuration
    `#define` DDP_ID_STATUS 251   // 0xFB - Status information

    2. Does WLED's Network Output properly set dataType and destination? YES ✓

    WLED's DDP packet construction in udp.cpp lines 826-827 correctly writes:

    /*2*/ddpUdp.write(isRGBW ?  DDP_TYPE_RGBW32 : DDP_TYPE_RGB24);  // dataType
    /*3*/ddpUdp.write(DDP_ID_DISPLAY);                               // destination = 1

    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.
    
  12. netmindz commented on Feb 20, 2026

    @netmindz
    Member

    @coderabbitai here's my thought:

    1. 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)

    Please correct your learning @coderabbitai

  13. coderabbitai commented on Feb 20, 2026

    @coderabbitai
    Contributor

    @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:

    static void handleDDPPacket(e131_packet_t* p) {
      // Reject non-display packets
      if (p->destination != DDP_ID_DISPLAY) {
        DEBUG_PRINTLN(F("DDP: Not for display, ignoring packet"));
        return;
      }
      
      // Validate data type
      uint8_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.
    
  14. DedeHai commented on Feb 20, 2026

    @DedeHai
    Collaborator

    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.
  15. softhack007 commented on Feb 20, 2026

    @softhack007
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions