<commit_before>// Copyright 2013 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "syzygy/agent/asan/nested_heap.h"

#include <algorithm>

#include "base/bits.h"
#include "gtest/gtest.h"
#include "syzygy/agent/asan/asan_heap.h"
#include "syzygy/agent/asan/asan_rtl_impl.h"
#include "syzygy/agent/asan/asan_runtime.h"
#include "syzygy/agent/asan/asan_shadow.h"
#include "syzygy/agent/asan/unittest_util.h"
#include "syzygy/common/align.h"

namespace agent {
namespace asan {

namespace {

class NestedHeapTest : public testing::Test {
 public:
  void SetUp() OVERRIDE {
    testing::Test::SetUp();
    runtime_.SetUp(std::wstring());
    agent::asan::SetUpRtl(&runtime_);
  }

  void TearDown() OVERRIDE {
    agent::asan::TearDownRtl();
    runtime_.TearDown();
    testing::Test::TearDown();
  }

  static const size_t kMaxAlignment = 2048;
  static const size_t kBufferSize = kMaxAlignment * 2;

  bool MemoryRangeIsPoisoned(const uint8* address, size_t size) {
    EXPECT_TRUE(address != NULL);
    for (size_t i = 0; i < size; ++i) {
      if (Shadow::IsAccessible(address + i))
        return false;
    }
    return true;
  }

  bool MemoryRangeIsAccessible(const uint8* address, size_t size) {
    EXPECT_TRUE(address != NULL);<commit_msg>Fix a bug in the nested heap unittests.<commit_after>// Copyright 2013 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "syzygy/agent/asan/nested_heap.h"

#include <algorithm>

#include "base/bits.h"
#include "gtest/gtest.h"
#include "syzygy/agent/asan/asan_heap.h"
#include "syzygy/agent/asan/asan_rtl_impl.h"
#include "syzygy/agent/asan/asan_runtime.h"
#include "syzygy/agent/asan/asan_shadow.h"
#include "syzygy/agent/asan/unittest_util.h"
#include "syzygy/common/align.h"

namespace agent {
namespace asan {

namespace {

class NestedHeapTest : public testing::Test {
 public:
  void SetUp() OVERRIDE {
    testing::Test::SetUp();
    runtime_.SetUp(std::wstring());
    agent::asan::SetUpRtl(&runtime_);
  }

  void TearDown() OVERRIDE {
    agent::asan::TearDownRtl();
    runtime_.TearDown();
    testing::Test::TearDown();
  }

  static const size_t kMaxAlignment = 2048;
  // If we want to test the alignments up to 2048 we need a buffer of at least
  // 3 * 2048 bytes:
  // +--- 0 <= size < 2048 bytes---+---2048 bytes---+--2048 bytes--+
  // ^buffer                       ^aligned_buffer  ^user_pointer
  static const size_t kBufferSize = kMaxAlignment * 3;

  bool MemoryRangeIsPoisoned(const uint8* address, size_t size) {
    EXPECT_TRUE(address != NULL);
    for (size_t i = 0; i < size; ++i) {
      if (Shadow::IsAccessible(address + i))
        return false;
    }
    return true;
  }

  bool MemoryRangeIsAccessible(const uint8* address, size_t size) {
    EXPECT_TRUE(address != NULL);
{'fraction_non_alphanumeric': 0.12263417163598651, 'fraction_numerical': 0.014000518537723619, 'mean_word_length': 3.6314525810324128, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6020890', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1224, 'n_words': 373}