You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "James E. King III (JIRA)" <ji...@apache.org> on 2019/01/26 15:09:00 UTC
[jira] [Closed] (THRIFT-1156) Bug with Base 64 coding in
TBase64Utils
[ https://issues.apache.org/jira/browse/THRIFT-1156?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
James E. King III closed THRIFT-1156.
-------------------------------------
Resolution: Duplicate
Assignee: James E. King III
Fix Version/s: 0.9
> Bug with Base 64 coding in TBase64Utils
> ---------------------------------------
>
> Key: THRIFT-1156
> URL: https://issues.apache.org/jira/browse/THRIFT-1156
> Project: Thrift
> Issue Type: Bug
> Components: Java - Library
> Affects Versions: 0.6
> Environment: Java SE, Android
> Reporter: Głowka Rafał
> Assignee: James E. King III
> Priority: Major
> Fix For: 0.9
>
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> There are some problems with coding byte[] when values are less that 0.
> The example code :
> public static void main(String[] args)
> {
> byte[] data = new byte[256];
> byte[] data2 = new byte[512];
> for (int i = 0; i < 512; i++)
> data2[i] = 0;
> for (byte b = -128; b < 127; b++)
> data[b + 128] = b;
> int len = 256;
> int off = 0;
> int off2 = 0;
> while (len >= 3) {
> // Encode 3 bytes at a time
> TBase64Utils.encode(data, off, 3, data2, off2);
> off += 3;
> off2 += 4;
> len -= 3;
> }
> if (len > 0) {
> // Encode remainder
> TBase64Utils.encode(data, off, len, data2, off2);
> }
> len = 256;
> off = 0;
> off2 = 0;
> while (len >= 3) {
> // Encode 3 bytes at a time
> TBase64Utils.decode(data2, off2, 4, data, off);
> off += 3;
> len -= 3;
> off2 += 4;
> }
> if (len > 0) {
> // Encode remainder
> TBase64Utils.decode(data2, off2, len, data, off);
> }
> for (byte b = -128; b < 127; b++)
> System.out.println("should be : " + (b) + " is : " + data[b + 128]);
> }
> The results :
> ...
> should be : -18 is : -18
> should be : -17 is : -18
> should be : -16 is : -1
> should be : -15 is : -15
> should be : -14 is : -15
> should be : -13 is : -14
> should be : -12 is : -12
> should be : -11 is : -12
> should be : -10 is : -11
> should be : -9 is : -9
> should be : -8 is : -5
> should be : -7 is : -8
> should be : -6 is : -6
> should be : -5 is : -6
> should be : -4 is : -5
> should be : -3 is : -3
> should be : -2 is : -3
> should be : -1 is : -1
> should be : 0 is : 0
> should be : 1 is : 1
> ...
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)