Skip to content

Commit 119bcc9

Browse files
Copilotmouse07410
andcommitted
Fix partial decoding issues for large and truncated messages
- Add partial_printed flag to track if results were already shown - Only print partial results in RC_WMORE handler when EOF is hit (rd==0) - Check partial_printed flag to prevent duplicate output - Fixes false positives for large messages that need multiple buffer reads - Fixes duplicate output for truncated messages Co-authored-by: mouse07410 <5923577+mouse07410@users.noreply.github.com>
1 parent 739296c commit 119bcc9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

skeletons/converter-example.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,8 @@ data_decode_from_file(enum asn_transfer_syntax isyntax, asn_TYPE_descriptor_t *p
889889
rval.code = RC_WMORE;
890890
rval.consumed = 0;
891891

892+
int partial_printed = 0; /* Track if we already printed partial results */
893+
892894
for(tolerate_eof = 1; /* Allow EOF first time buffer is non-empty */
893895
(rd = fread(fbuf, 1, fbuf_size, file))
894896
|| feof(file) == 0
@@ -950,10 +952,12 @@ data_decode_from_file(enum asn_transfer_syntax isyntax, asn_TYPE_descriptor_t *p
950952
}
951953
if(rval.code == RC_WMORE && !restartability_supported(isyntax)) {
952954
/* PER does not support restartability */
953-
if(opt_partial && structure) {
955+
/* Only print partial results if we've hit EOF (rd == 0) and haven't printed yet */
956+
if(opt_partial && structure && rd == 0 && !partial_printed) {
954957
fprintf(stderr, "\n=== Partial Decoding Results (RC_WMORE) ===\n");
955958
asn_fprint(stderr, pduType, structure);
956959
fprintf(stderr, "=== End of Partial Results ===\n\n");
960+
partial_printed = 1; /* Mark that we've printed partial results */
957961
}
958962
ASN_STRUCT_FREE(*pduType, structure);
959963
structure = 0;
@@ -1014,8 +1018,8 @@ data_decode_from_file(enum asn_transfer_syntax isyntax, asn_TYPE_descriptor_t *p
10141018

10151019
DEBUG("Clean up partially decoded %s", pduType->name);
10161020

1017-
/* If partial decoding option is enabled, print what we decoded so far */
1018-
if(opt_partial && structure) {
1021+
/* If partial decoding option is enabled and we haven't already printed, print what we decoded so far */
1022+
if(opt_partial && structure && !partial_printed) {
10191023
fprintf(stderr, "\n=== Partial Decoding Results ===\n");
10201024
asn_fprint(stderr, pduType, structure);
10211025
fprintf(stderr, "=== End of Partial Results ===\n\n");

0 commit comments

Comments
 (0)