Skip to content

Commit

Permalink
Merge pull request #1476 from CastagnaIT/android_secure_nexus
Browse files Browse the repository at this point in the history
[backport][Widevine] Fix wrong byte position of clearbytes data array
  • Loading branch information
CastagnaIT authored Feb 19, 2024
2 parents a8af376 + f102944 commit 96d14d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions wvdecrypter/wvdecrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,9 @@ AP4_Result WV_CencSingleSampleDecrypter::DecryptSampleData(AP4_UI32 pool_id,
{
//check NAL / subsample
const AP4_Byte *packet_in(data_in.GetData()), *packet_in_e(data_in.GetData() + data_in.GetDataSize());
unsigned int clrbPos = sizeof(subsample_count);
// Byte position of "bytesOfCleartextData" where to set the size of the data,
// by default starts after the subsample count data (so the size of subsample_count data type)
size_t clrDataBytePos = sizeof(subsample_count);
// unsigned int nalunitcount(0);
unsigned int nalunitsum(0);
// unsigned int configSize(0);
Expand All @@ -1181,7 +1183,8 @@ AP4_Result WV_CencSingleSampleDecrypter::DecryptSampleData(AP4_UI32 pool_id,
fragInfo.annexb_sps_pps_.GetDataSize());
if (iv)
{
AP4_UI16* clrb_out = reinterpret_cast<AP4_UI16*>(data_out.UseData() + clrbPos);
// Update the byte containing the data size of current subsample referred to clear bytes array
AP4_UI16* clrb_out = reinterpret_cast<AP4_UI16*>(data_out.UseData() + clrDataBytePos);
*clrb_out += fragInfo.annexb_sps_pps_.GetDataSize();
}

Expand All @@ -1197,7 +1200,8 @@ AP4_Result WV_CencSingleSampleDecrypter::DecryptSampleData(AP4_UI32 pool_id,

if (iv)
{
AP4_UI16* clrb_out = reinterpret_cast<AP4_UI16*>(data_out.UseData() + clrbPos);
// Update the byte containing the data size of current subsample referred to clear bytes array
AP4_UI16* clrb_out = reinterpret_cast<AP4_UI16*>(data_out.UseData() + clrDataBytePos);
*clrb_out += (4 - fragInfo.nal_length_size_);
}

Expand All @@ -1215,7 +1219,7 @@ AP4_Result WV_CencSingleSampleDecrypter::DecryptSampleData(AP4_UI32 pool_id,
summedBytes += *bytes_of_cleartext_data + *bytes_of_encrypted_data;
++bytes_of_cleartext_data;
++bytes_of_encrypted_data;
++clrbPos;
clrDataBytePos += sizeof(AP4_UI16); // Move to the next clear data subsample byte position
--subsample_count;
} while (subsample_count && nalsize + fragInfo.nal_length_size_ + nalunitsum > summedBytes);

Expand Down
12 changes: 8 additions & 4 deletions wvdecrypter/wvdecrypter_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,9 @@ AP4_Result WV_CencSingleSampleDecrypter::DecryptSampleData(AP4_UI32 pool_id,
{
//check NAL / subsample
const AP4_Byte *packet_in(data_in.GetData()), *packet_in_e(data_in.GetData() + data_in.GetDataSize());
unsigned int clrbPos = sizeof(subsample_count);
// Byte position of "bytesOfCleartextData" where to set the size of the data,
// by default starts after the subsample count data (so the size of subsample_count data type)
size_t clrDataBytePos = sizeof(subsample_count);
// unsigned int nalunitcount(0);
unsigned int nalunitsum(0);
// unsigned int configSize(0);
Expand All @@ -1142,7 +1144,8 @@ AP4_Result WV_CencSingleSampleDecrypter::DecryptSampleData(AP4_UI32 pool_id,
fragInfo.annexb_sps_pps_.GetDataSize());
if (iv)
{
AP4_UI16* clrb_out = reinterpret_cast<AP4_UI16*>(data_out.UseData() + clrbPos);
// Update the byte containing the data size of current subsample referred to clear bytes array
AP4_UI16* clrb_out = reinterpret_cast<AP4_UI16*>(data_out.UseData() + clrDataBytePos);
*clrb_out += fragInfo.annexb_sps_pps_.GetDataSize();
}

Expand All @@ -1158,7 +1161,8 @@ AP4_Result WV_CencSingleSampleDecrypter::DecryptSampleData(AP4_UI32 pool_id,

if (iv)
{
AP4_UI16* clrb_out = reinterpret_cast<AP4_UI16*>(data_out.UseData() + clrbPos);
// Update the byte containing the data size of current subsample referred to clear bytes array
AP4_UI16* clrb_out = reinterpret_cast<AP4_UI16*>(data_out.UseData() + clrDataBytePos);
*clrb_out += (4 - fragInfo.nal_length_size_);
}

Expand All @@ -1176,7 +1180,7 @@ AP4_Result WV_CencSingleSampleDecrypter::DecryptSampleData(AP4_UI32 pool_id,
summedBytes += *bytes_of_cleartext_data + *bytes_of_encrypted_data;
++bytes_of_cleartext_data;
++bytes_of_encrypted_data;
++clrbPos;
clrDataBytePos += sizeof(AP4_UI16); // Move to the next clear data subsample byte position
--subsample_count;
} while (subsample_count && nalsize + fragInfo.nal_length_size_ + nalunitsum > summedBytes);

Expand Down

0 comments on commit 96d14d4

Please sign in to comment.