Skip to content

Commit

Permalink
fixing input validation in segments and delete pit request (opensearc…
Browse files Browse the repository at this point in the history
…h-project#6645)

* fixing input validation in segments and delete pit request

Signed-off-by: Bharathwaj G <[email protected]>
  • Loading branch information
bharath-techie authored May 25, 2023
1 parent cf02b96 commit c41c5c2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Replaces ZipInputStream with ZipFile to fix Zip Slip vulnerability ([#7230](https://github.com/opensearch-project/OpenSearch/pull/7230))
- Add missing validation/parsing of SearchBackpressureMode of SearchBackpressureSettings ([#7541](https://github.com/opensearch-project/OpenSearch/pull/7541))
- [Search Pipelines] Better exception handling in search pipelines ([#7735](https://github.com/opensearch-project/OpenSearch/pull/7735))
- Fix input validation in segments and delete pit request ([#6645](https://github.com/opensearch-project/OpenSearch/pull/6645))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static org.opensearch.action.search.SearchContextId.decode;
Expand Down Expand Up @@ -94,8 +96,7 @@ public TransportPitSegmentsAction(
*/
@Override
protected void doExecute(Task task, PitSegmentsRequest request, ActionListener<IndicesSegmentResponse> listener) {
List<String> pitIds = request.getPitIds();
if (pitIds.size() == 1 && "_all".equals(pitIds.get(0))) {
if (request.getPitIds().size() == 1 && "_all".equals(request.getPitIds().get(0))) {
pitService.getAllPits(ActionListener.wrap(response -> {
request.clearAndSetPitIds(response.getPitInfos().stream().map(ListPitInfo::getPitId).collect(Collectors.toList()));
super.doExecute(task, request, listener);
Expand All @@ -114,7 +115,9 @@ protected void doExecute(Task task, PitSegmentsRequest request, ActionListener<I
@Override
protected ShardsIterator shards(ClusterState clusterState, PitSegmentsRequest request, String[] concreteIndices) {
final ArrayList<ShardRouting> iterators = new ArrayList<>();
for (String pitId : request.getPitIds()) {
// remove duplicates from the request
Set<String> uniquePitIds = new LinkedHashSet<>(request.getPitIds());
for (String pitId : uniquePitIds) {
SearchContextId searchContext = decode(namedWriteableRegistry, pitId);
for (Map.Entry<ShardId, SearchContextIdForNode> entry : searchContext.shards().entrySet()) {
final SearchContextIdForNode perNode = entry.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
Expand All @@ -46,8 +48,7 @@ public TransportDeletePitAction(
*/
@Override
protected void doExecute(Task task, DeletePitRequest request, ActionListener<DeletePitResponse> listener) {
List<String> pitIds = request.getPitIds();
if (pitIds.size() == 1 && "_all".equals(pitIds.get(0))) {
if (request.getPitIds().size() == 1 && "_all".equals(request.getPitIds().get(0))) {
deleteAllPits(listener);
} else {
deletePits(listener, request);
Expand All @@ -59,7 +60,9 @@ protected void doExecute(Task task, DeletePitRequest request, ActionListener<Del
*/
private void deletePits(ActionListener<DeletePitResponse> listener, DeletePitRequest request) {
Map<String, List<PitSearchContextIdForNode>> nodeToContextsMap = new HashMap<>();
for (String pitId : request.getPitIds()) {
// remove duplicates from the request
Set<String> uniquePitIds = new LinkedHashSet<>(request.getPitIds());
for (String pitId : uniquePitIds) {
SearchContextId contextId = SearchContextId.decode(namedWriteableRegistry, pitId);
for (SearchContextIdForNode contextIdForNode : contextId.shards().values()) {
PitSearchContextIdForNode pitSearchContext = new PitSearchContextIdForNode(pitId, contextIdForNode);
Expand Down

0 comments on commit c41c5c2

Please sign in to comment.