Add auto buffer resize for SourceLength in EKLV reading #154
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR extends the automatic buffer resizing functionality to the
SourceLengthcheck within theRead_EKLV_Packetfunction.Previously, if the provided
FrameBufhad insufficient capacity forSourceLength(even if it owned its memory), the function would immediately returnRESULT_SMALLBUF. This change introduces an attempt to resize the buffer automatically in such cases.Changes
Read_EKLV_Packetinh__Reader.cpp:FrameBuf.Capacity()is less thanSourceLength, the code now attempts to resizeFrameBuftoSourceLength.FrameBufowns its memory andmallocsucceeds), a warning is logged, and processing continues.FrameBufuses external memory ormallocfails), an error is logged, andRESULT_SMALLBUFis 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
SourceLengthcheck with similar resizing logic implemented forPacketLengthin other parts of the frame reading process, providing more consistent and user-friendly behavior.Impact
RESULT_SMALLBUFerrors whenFrameBufowns its memory and can be resized.Read_EKLV_Packet.FrameBufuses an externally managed buffer or if memory allocation for resizing fails.