storm icon indicating copy to clipboard operation
storm copied to clipboard

[STORM-3753] Change String.getBytes() to DFSUtil.string2Bytes(String)…

Open dbgp2021 opened this issue 3 years ago • 1 comments

… to avoid Unsupported Encoding Exception

Hello, I found that DFSUtil.string2Bytes(String) can be used here instead of String.getBytes(). Otherwise, the API String.getBytes() may cause potential risk of UnsupportedEncodingException since the behavior of this method when the string cannot be encoded in the default charset is unspecified. One recommended API is DFSUtil.string2Bytes(String) which provides more control over the encoding process and can avoid this exception.

dbgp2021 avatar Mar 18 '21 03:03 dbgp2021

Hi @Ethanlm , thanks for your recommendation, I have changed the code correspondingly, which use data.getBytes(xxx). Please review.

Currently, I do not have a test case for this, but a very similar one can be found here: https://github.com/apache/hadoop/commit/ab3885f2c8cfd63ff94e548c40db3b4ea52c12e8 .

I believe that providing the encoding is a good way to make the code more robust.

Please kindly check. Thanks.

dbgp2021 avatar Apr 12 '21 05:04 dbgp2021

There are other locations where the default encoding of the OS is used to create String instances. Would you like to take a look and rebase @dbgp2021 ?

rzo1 avatar Aug 25 '23 10:08 rzo1

Eventhubs was removed with https://issues.apache.org/jira/projects/STORM/issues/STORM-3988?filter=allissues

rzo1 avatar Oct 23 '23 14:10 rzo1