-
Notifications
You must be signed in to change notification settings - Fork 77
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
MXF parsing: terminate strings on the first null character #373
Conversation
* | ||
* @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]; |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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)
There was a problem hiding this 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.
57354c6
to
d22671f
Compare
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) ) |
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