@@ -683,7 +683,10 @@ static void* sqlite3Codec(void *iCtx, void *data, Pgno pgno, int mode) {
683683 memcpy (buffer , plaintext_header_sz ? pData : (void * ) SQLITE_FILE_HEADER , offset );
684684
685685 rc = sqlcipher_page_cipher (ctx , cctx , pgno , CIPHER_DECRYPT , page_sz - offset , pData + offset , (unsigned char * )buffer + offset );
686- if (rc != SQLITE_OK ) sqlcipher_codec_ctx_set_error (ctx , rc );
686+ if (rc != SQLITE_OK ) { /* clear results of failed cipher operation and set error */
687+ sqlcipher_memset (buffer + offset , 0 , page_sz - offset );
688+ sqlcipher_codec_ctx_set_error (ctx , rc );
689+ }
687690 memcpy (pData , buffer , page_sz ); /* copy buffer data back to pData and return */
688691 return pData ;
689692 break ;
@@ -702,7 +705,10 @@ static void* sqlite3Codec(void *iCtx, void *data, Pgno pgno, int mode) {
702705 memcpy (buffer , plaintext_header_sz ? pData : kdf_salt , offset );
703706 }
704707 rc = sqlcipher_page_cipher (ctx , cctx , pgno , CIPHER_ENCRYPT , page_sz - offset , pData + offset , (unsigned char * )buffer + offset );
705- if (rc != SQLITE_OK ) sqlcipher_codec_ctx_set_error (ctx , rc );
708+ if (rc != SQLITE_OK ) { /* clear results of failed cipher operation and set error */
709+ sqlcipher_memset (buffer + offset , 0 , page_sz - offset );
710+ sqlcipher_codec_ctx_set_error (ctx , rc );
711+ }
706712 return buffer ; /* return persistent buffer data, pData remains intact */
707713 break ;
708714
0 commit comments