• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

frameworks/av


Commit MetaInfo

Revision7e354f50d3017c8b392c8e10ed940984473e5af1 (tree)
Time2015-09-29 08:27:08
AuthorWonsik Kim <wonsik@goog...>
CommiterThe Android Automerger

Log Message

Ogg: avoid size_t overflow in base64 decoding

Bug: 23707088
Change-Id: I8d32841fee3213c721cdcc57788807ea64d19d74

Change Summary

Incremental Difference

--- a/media/libstagefright/OggExtractor.cpp
+++ b/media/libstagefright/OggExtractor.cpp
@@ -893,11 +893,14 @@ static uint8_t *DecodeBase64(const char *s, size_t size, size_t *outSize) {
893893 }
894894 }
895895
896- size_t outLen = 3 * size / 4 - padding;
897-
898- *outSize = outLen;
896+ // We divide first to avoid overflow. It's OK to do this because we
897+ // already made sure that size % 4 == 0.
898+ size_t outLen = (size / 4) * 3 - padding;
899899
900900 void *buffer = malloc(outLen);
901+ if (buffer == NULL) {
902+ return NULL;
903+ }
901904
902905 uint8_t *out = (uint8_t *)buffer;
903906 size_t j = 0;
@@ -916,10 +919,10 @@ static uint8_t *DecodeBase64(const char *s, size_t size, size_t *outSize) {
916919 } else if (c == '/') {
917920 value = 63;
918921 } else if (c != '=') {
919- return NULL;
922+ break;
920923 } else {
921924 if (i < n - padding) {
922- return NULL;
925+ break;
923926 }
924927
925928 value = 0;
@@ -937,6 +940,13 @@ static uint8_t *DecodeBase64(const char *s, size_t size, size_t *outSize) {
937940 }
938941 }
939942
943+ // Check if we exited the loop early.
944+ if (j < outLen) {
945+ free(buffer);
946+ return NULL;
947+ }
948+
949+ *outSize = outLen;
940950 return (uint8_t *)buffer;
941951 }
942952