Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valid cursor at end-of-input results in same Tell output as error state #230

Closed
BrianSipos opened this issue May 28, 2024 · 1 comment
Closed

Comments

@BrianSipos
Copy link
Contributor

I appreciate the quick changes made in #223 to provide visibility into the internal cursor.

The current API, which is accurately documented in the header below, makes it impossible to distinguish between the error state and a valid cursor positioned at the end-of-input.

QCBOR/inc/qcbor/qcbor_decode.h

Lines 1054 to 1056 in b239c65

* would be next decoded with QCBORDecode_VGetNext(). If the cursor
* is at the end of the input or in the error state, @c UINT32_MAX is
* returned.

In my use of this function, I need to undo the following conversion logic and requires an additional call into UsefulInputBuf_GetBufferLength(). It seems to me that this logic is not really necessary and is not as efficient as simply not including this block (and updating the documentation appropriately). The reason is that a cursor at the end-of-input is perfectly valid situation to be in, and if a user application cares about this condition it can detect it as it needs to.

QCBOR/src/qcbor_decode.c

Lines 3167 to 3172 in b239c65

if(uCursorOffset == UsefulInputBuf_GetBufferLength(&(pMe->InBuf))) {
return UINT32_MAX;
} else {
/* Cast is safe because decoder input size is restricted. */
return (uint32_t)uCursorOffset;
}

@laurencelundblade
Copy link
Owner

Understand your request and kind of thought about that in the back of my mind when I made the change. Thinking about it...

laurencelundblade added a commit that referenced this issue Jun 16, 2024
QCBORDecode_Tell() returns the offset when at the end of the input rather than UINT32_MAX. This is a non-compatible change, but QCBORDecode_Tell() was very recently introduced and is not present in any official releases.

QCBORDecode_EndCheck() is added to check to see if the cursor is at the end of the input.

Addresses #230


* Add EndCheck(); change Tell() behavior

* Minor corrections

* Minor doc update

---------

Co-authored-by: Laurence Lundblade <lgl@securitytheory.com>
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

No branches or pull requests

2 participants