summaryrefslogtreecommitdiff
path: root/jni/include
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2020-10-06 09:15:34 +0100
committerNarayan Kamath <narayan@google.com>2020-10-06 11:41:41 +0100
commit11700c0f4057ebc61f10d50384760e1156b91090 (patch)
treec99efaffb4ec4ee9cce8f8df3b83d93d0037f5b9 /jni/include
parent438eceec7e431cae18c2a1e2afe97a4a29a2965a (diff)
downloadMediaProvider-11700c0f4057ebc61f10d50384760e1156b91090.tar.gz
Fix Redaction calculation.
The redaction code in the FUSE daemon made mistaken assumptions about the ranges returned by ExifInterface, particularly that they were inclusive of the end index. This sometimes leads to extra bytes being redacted. The code has now been revamped to be clearer and better tested.. Test: atest RedactionInfoTest Test: atest ScopedStorageTest Bug: 169389401 Change-Id: I7ff2107cb62629b3ec7d9beba898d688a3aa1add
Diffstat (limited to 'jni/include')
-rw-r--r--jni/include/libfuse_jni/RedactionInfo.h47
1 files changed, 33 insertions, 14 deletions
diff --git a/jni/include/libfuse_jni/RedactionInfo.h b/jni/include/libfuse_jni/RedactionInfo.h
index 5218e28a6..fe475cba4 100644
--- a/jni/include/libfuse_jni/RedactionInfo.h
+++ b/jni/include/libfuse_jni/RedactionInfo.h
@@ -17,19 +17,31 @@
#ifndef MEDIA_PROVIDER_FUSE_REDACTIONINFO_H_
#define MEDIA_PROVIDER_FUSE_REDACTIONINFO_H_
+#include <ostream>
#include <vector>
namespace mediaprovider {
namespace fuse {
/**
- * Type that represents a single redaction range within a file.
- * first is the offset of the first byte in the redaction range within the file
- * second is the offset of the last byte in the redaction range within the file
- * Ranges are inclusive.
+ * Type that represents a single redaction range within a file. Contains
+ * a pair of offsets in the file, [start, end).
*/
typedef std::pair<off64_t, off64_t> RedactionRange;
+class ReadRange {
+ public:
+ ReadRange(off64_t s, size_t l, bool r) : start(s), size(l), is_redaction(r) {}
+
+ const off64_t start;
+ const size_t size;
+ const bool is_redaction;
+
+ bool operator==(const ReadRange& rhs) const {
+ return start == rhs.start && size == rhs.size && is_redaction == rhs.is_redaction;
+ }
+};
+
class RedactionInfo {
public:
/**
@@ -55,6 +67,23 @@ class RedactionInfo {
* Calls d'tor for redactionRanges (vector).
*/
~RedactionInfo() = default;
+
+ /**
+ * Returns a set of ranges to fulfill a read request starting at |off| of size
+ * |size|.
+ */
+ void getReadRanges(off64_t off, size_t size, std::vector<ReadRange>* out) const;
+
+ /**
+ * Returns whether any ranges need to be redacted.
+ */
+ bool isRedactionNeeded() const;
+ /**
+ * Returns number of redaction ranges.
+ */
+ int size() const;
+
+ private:
/**
* Calculates the redaction ranges that overlap with a given read request.
* The read request is defined by its size and the offset of its first byte.
@@ -70,16 +99,6 @@ class RedactionInfo {
*/
std::unique_ptr<std::vector<RedactionRange>> getOverlappingRedactionRanges(size_t size,
off64_t off) const;
- /**
- * Returns whether any ranges need to be redacted.
- */
- bool isRedactionNeeded() const;
- /**
- * Returns number of redaction ranges.
- */
- int size() const;
-
- private:
std::vector<RedactionRange> redaction_ranges_;
void processRedactionRanges(int redaction_ranges_num, const off64_t* redaction_ranges);
bool hasOverlapWithReadRequest(size_t size, off64_t off) const;