Skip to content

Conversation

@RealAdarsh
Copy link
Contributor

Description

This PR extends the automatic buffer resizing functionality to the SourceLength check within the Read_EKLV_Packet function.

Previously, if the provided FrameBuf had insufficient capacity for SourceLength (even if it owned its memory), the function would immediately return RESULT_SMALLBUF. This change introduces an attempt to resize the buffer automatically in such cases.

Changes

  • Modified Read_EKLV_Packet in h__Reader.cpp:
    • When FrameBuf.Capacity() is less than SourceLength, the code now attempts to resize FrameBuf to SourceLength.
    • If resizing is successful (i.e., FrameBuf owns its memory and malloc succeeds), a warning is logged, and processing continues.
    • If resizing fails (e.g., FrameBuf uses external memory or malloc fails), an error is logged, and RESULT_SMALLBUF is returned, maintaining the previous behavior for unrecoverable scenarios.

Reason for Change

This change enhances the robustness of the EKLV packet reading by allowing the library to handle cases where an initially undersized (but resizable) buffer is provided for the frame data. It aligns the behavior of the SourceLength check with similar resizing logic implemented for PacketLength in other parts of the frame reading process, providing more consistent and user-friendly behavior.

Impact

  • Reduces occurrences of RESULT_SMALLBUF errors when FrameBuf owns its memory and can be resized.
  • Improves consistency in buffer handling within Read_EKLV_Packet.
  • No change in behavior if FrameBuf uses an externally managed buffer or if memory allocation for resizing fails.

@RealAdarsh
Copy link
Contributor Author

Hi @jhursty

Could you please take a look at this PR? If you think any changes are needed, kindly let me know. I’m happy to address any feedback!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant