intl/uconv/src/nsReplacementToUnicode.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include "nsReplacementToUnicode.h"
     7 nsReplacementToUnicode::nsReplacementToUnicode()
     8  : mSeenByte(false)
     9 {
    10 }
    12 NS_IMETHODIMP
    13 nsReplacementToUnicode::Convert(const char* aSrc,
    14                                 int32_t* aSrcLength,
    15                                 char16_t* aDest,
    16                                 int32_t* aDestLength)
    17 {
    18   if (mSeenByte || !(*aSrcLength)) {
    19     *aDestLength = 0;
    20     return NS_PARTIAL_MORE_INPUT;
    21   }
    22   if (mErrBehavior == kOnError_Signal) {
    23     mSeenByte = true;
    24     *aSrcLength = 0;
    25     *aDestLength = 0;
    26     return NS_ERROR_ILLEGAL_INPUT;
    27   }
    28   if (!(*aDestLength)) {
    29     *aSrcLength = -1;
    30     return NS_PARTIAL_MORE_OUTPUT;
    31   }
    32   mSeenByte = true;
    33   *aDest = 0xFFFD;
    34   *aDestLength = 1;
    35   return NS_PARTIAL_MORE_INPUT;
    36 }
    38 NS_IMETHODIMP
    39 nsReplacementToUnicode::GetMaxLength(const char* aSrc,
    40                           int32_t aSrcLength,
    41                           int32_t* aDestLength)
    42 {
    43   if (!mSeenByte && aSrcLength > 0) {
    44     *aDestLength = 1;
    45   } else {
    46     *aDestLength = 0;
    47   }
    48   return NS_EXACT_LENGTH;
    49 }
    51 NS_IMETHODIMP
    52 nsReplacementToUnicode::Reset()
    53 {
    54   mSeenByte = false;
    55   return NS_OK;
    56 }

mercurial