Skip to content

Commit

Permalink
MXF parsing: terminate strings on the first null character
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thomasheritage committed Jun 26, 2024
1 parent beda248 commit 57354c6
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@ else if ((field.getType() == Boolean.class) && (byteArraySize == 1))
}

/**
* Getter for a string representing the byte[]
* Getter for a string representing the byte[], terminating on the first null character
*
* @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];
}

/**
Expand Down

0 comments on commit 57354c6

Please sign in to comment.