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

MXF parsing: terminate strings on the first null character #373

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

thomasheritage
Copy link
Contributor

Per SMPTE ST 377-1:2019, a "zero value" can be used to terminate a string.

So, discard any data after the first null character found (if any).

This has the same effect as the implementation for strings in regxmllib at: https://github.com/sandflow/regxmllib/blob/b47b0cdbd6dbf51cae4fb14c3a6a827eb3e0e2cc/src/main/java/com/sandflow/smpte/regxml/FragmentBuilder.java#L902

Note that regxmllib also uses the same readCharacters method for MXF properties with a Type of Type Kind "Character", and allows values of this Type to contain the null character.
Photon does not support such "Character" Types (and indeed none have ever been used in MXF according to the SMPTE Metadata Registers). So, no consideration is given to these Types in this patch.

Closes #372

*
* @param byteArray the byte array
* @param charset the charset
* @return the string
*/
public static String getString(byte[] byteArray, Charset charset)
{
return new String(byteArray, charset);
return new String(byteArray, charset).split("\u0000", 2)[0];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not in love with the split.

What about?

         String s = String(byteArray, charset);

         int i = s.indexOf('\u0000');

        if (i== -1) {
            return s;
        }

        return s.substring(0, i);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, that looks fine (it appears to be functionally equivalent) (except that I believe there should be a new in the first line)

Copy link
Collaborator

@palemieux palemieux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test case should ideally be added.

Per SMPTE ST 377-1:2019, a "zero value" can be used to terminate a
string.

So, discard any data after the first null character found (if any).

This has the same effect as the implementation for strings in regxmllib at:
https://github.com/sandflow/regxmllib/blob/b47b0cdbd6dbf51cae4fb14c3a6a827eb3e0e2cc/src/main/java/com/sandflow/smpte/regxml/FragmentBuilder.java#L902

Note that regxmllib also uses the same `readCharacters` method for MXF
properties with a Type of Type Kind "Character", and allows values of
this Type to contain the null character.
Photon does not support such "Character" Types (and indeed none have ever been used
in MXF according to the SMPTE Metadata Registers). So, no consideration
is given to these Types in this patch.
@thomasheritage
Copy link
Contributor Author

I've updated the branch to amend the code and add a test (with a small MXF file containing Header Metadata with strings that are null terminated: prior to the code fix an error was given by Photon for this file per #372 (comment) )

@fschleich fschleich merged commit 2ee9afa into Netflix:master Nov 20, 2024
1 check passed
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.

Handle MXF string termination to avoid incorrect validation errors
3 participants